Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How does VFP load class methods into memory?
Message
From
16/11/2009 09:31:05
 
 
To
16/11/2009 09:26:10
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01434853
Message ID:
01434931
Views:
41
>>>>>>Hi,
>>>>>>
>>>>>>I am thinking if it is better to break a class into two classes and have one inherit from another. Mainly I am considering this to see if I can speed up loading the objects using the class. I have not quantified the speed of loading the objects, this is just a guess that the speed can be improved. Some forms can have up to about 20 objects using this class (as base or are instantiated in the INIT method).
>>>>>>
>>>>>>The class has 16 methods. Only 8 of them are used in one part of the program. All 16 are used only in some other parts of the application. My question is, does VFP 9, when instantiating the class, loads the code from all 16 methods into memory? Or it only loads the method when the method is used?
>>>>>>
>>>>>>TIA.
>>>>>
>>>>>I wonder whether the number of methods (8 or 16 here) is going to influence the speed of instantiating the objects. The code is the same for any one class. So, I'd say that the methods are loaded only once and shared amongst the objects of the same class. The 'load more code' penalty, if any, only happens once imo
>>>>
>>>>Hi Gregory,
>>>>
>>>>I am not sure I understand/agree with you. Say, the class we are discussing has a method "MyMethod1". If a form uses 20 objects based on this class, the method "MyMethod1" is loaded 20 times, not one time, when the form is instantiated. Right?
>>>
>>>
>>>I think 'MyMethod1' is only loaded once - it's readonly code anyway
>>>
>>>I just did a test - based on http://fox.wikis.com/wc.dll?Wiki~TestMemoryCreateDestroy~VFP : function LogFunc(tcClass)
>>>
>>>
>>>10000 create/destroy 
>>>
>>>Class          memory
>>>MyClass     6236860
>>>MyClass2   6290496
>>>
>>>(6290496-6236860)/10000 = 5.36 bytes
>>>
>>>
>>>
>>>The compiled code of MyClass2 is about 128 k
>>>
>>>
>>>define class MyClass as relation
>>>
>>>
>>>enddefine
>>>
>>>
>>>
>>>
>>>
>>>define class MyClass2 as relation
>>>
>>>&& lots of functions
>>>enddefine
>>>
>>
>>Thank you for taking the time to illustrate the point. Would it be correct to assume that when a bunch of objects based on the same class are instantiated (one after the other) the first one takes longer time (relatively) to load and the following ones are less time (because the class properties and methods are already in the memory)?
>
>I believe so - see point #2
>
>
>http://fox.wikis.com/wc.dll?Wiki~VisualFoxproInvocationStack


It goes without saying that (1) only the class definition is kept in memory (2) the object properties are not shared. Properties have to be initialized each time
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform