Discussion:
[fpc-pascal] instance memory usage
Marc Santhoff
2018-10-20 18:09:01 UTC
Permalink
Hi,

from testing a while ago I remember the following:

The memory used by a class instance is composed of
1. the size ".instanceSize()" gives back
2. the memory used by other variables and maybe class instances referenced
by pointers and owned by the instance in question
3. strings are (to be) included in 2., string types are in fact references aka
pointers

The second clause is sort of "by definition", but I do define like that in
this case.

Is that listing correct and complete?

TIA,
Marc
--
Marc Santhoff <***@web.de>
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/
Sven Barth via fpc-pascal
2018-10-24 20:06:36 UTC
Permalink
Post by Marc Santhoff
Hi,
The memory used by a class instance is composed of
1. the size ".instanceSize()" gives back
2. the memory used by other variables and maybe class instances referenced
by pointers and owned by the instance in question
3. strings are (to be) included in 2., string types are in fact references aka
pointers
The second clause is sort of "by definition", but I do define like that in
this case.
Is that listing correct and complete?
The size InstanceSize() returns is the pointer to the VMT plus the size
of any field in the class or any of its parent classes as if it would be
a record (keep in mind that class references are merely pointers, so a
class having another as a field is merely a pointer, not its
InstanceSize(), the same is true for e.g. Ansi-/UnicodeString).

Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinf
Marc Santhoff
2018-10-24 22:52:19 UTC
Permalink
Post by Sven Barth via fpc-pascal
Post by Marc Santhoff
Hi,
The memory used by a class instance is composed of
1. the size ".instanceSize()" gives back
2. the memory used by other variables and maybe class instances referenced
by pointers and owned by the instance in question
3. strings are (to be) included in 2., string types are in fact references aka
pointers
The second clause is sort of "by definition", but I do define like that in
this case.
Is that listing correct and complete?
The size InstanceSize() returns is the pointer to the VMT plus the size
of any field in the class or any of its parent classes as if it would be
a record (keep in mind that class references are merely pointers, so a
class having another as a field is merely a pointer, not its
InstanceSize(), the same is true for e.g. Ansi-/UnicodeString).
OK, so my list is correct in general. The only thing missing would be the
code, but what I need to count is the data size when having lots of instance.
Post by Sven Barth via fpc-pascal
Regards,
Sven
Many thanks.
--
Marc Santhoff <***@web.de>
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pasc
Loading...