object size 
Author Message
 object size

When I'm debugging, is there any way to determine the runtime size (in
bytes) of an arbitrary object? My problem is that I'm allocating a large
number of elaborate objects (i.e. where it's tricky to figure out the
size by hand) and I need to know how much memory they'll cumulatively
suck up.

TIA



Mon, 03 Dec 2001 03:00:00 GMT  
 object size
Am I missing something?  Why not use sizeof()?

e.g.

size_t totalSize = sizeof(MyArbitraryObjectType) * count;

--

Steven S. Wolf
Senior Software Architect


Quote:
> When I'm debugging, is there any way to determine the runtime size (in
> bytes) of an arbitrary object? My problem is that I'm allocating a large
> number of elaborate objects (i.e. where it's tricky to figure out the
> size by hand) and I need to know how much memory they'll cumulatively
> suck up.

> TIA



Mon, 03 Dec 2001 03:00:00 GMT  
 object size
Some where I read that sizeof() does not report the size of an object
correctly. There is a function though, public static int sizeOf(Class
structCls), that may work.

--
URL: http://otool.hypermart.net/

Fax: (225)673-3062



Quote:
> Am I missing something?  Why not use sizeof()?

> e.g.

> size_t totalSize = sizeof(MyArbitraryObjectType) * count;

> --

> Steven S. Wolf
> Senior Software Architect



> > When I'm debugging, is there any way to determine the runtime size (in
> > bytes) of an arbitrary object? My problem is that I'm allocating a large
> > number of elaborate objects (i.e. where it's tricky to figure out the
> > size by hand) and I need to know how much memory they'll cumulatively
> > suck up.

> > TIA



Mon, 03 Dec 2001 03:00:00 GMT  
 object size
sizeof() "will" always work if it is used correctly.  You must consider of
course if your trying to sizeof a variable pointer or a structure enclosed
inside a #pragma pack(<?>) directives.  That would of course change the
return value.

struct a {
 BYTE b;

Quote:
};

struct a c;
struct a *d;

sizeof( c ) will return 1 and sizeof( d ) will return 4 of course.  It
depends on how you use it but I have never, ever seen sizeof() failing.  If
you have one example that fails... please post it back cause this is a
serious bug.

--

John Joelle Cruz
Software Engineer
Nortel Networks Inc.

[homepage] http://members.xoom.com/johncruise



Quote:
>Some where I read that sizeof() does not report the size of an object
>correctly. There is a function though, public static int sizeOf(Class
>structCls), that may work.

>--
>URL: http://otool.hypermart.net/

>Fax: (225)673-3062



>> Am I missing something?  Why not use sizeof()?

>> e.g.

>> size_t totalSize = sizeof(MyArbitraryObjectType) * count;

>> --

>> Steven S. Wolf
>> Senior Software Architect



>> > When I'm debugging, is there any way to determine the runtime size (in
>> > bytes) of an arbitrary object? My problem is that I'm allocating a
large
>> > number of elaborate objects (i.e. where it's tricky to figure out the
>> > size by hand) and I need to know how much memory they'll cumulatively
>> > suck up.

>> > TIA



Tue, 04 Dec 2001 03:00:00 GMT  
 object size
sizeof should work, unless of course you have pointers inside your class and
you want to count the size of these also. in this case you would have to add
up all the sizes of dynamically allocated memory.

vivek iyer
geometric

Quote:

>When I'm debugging, is there any way to determine the runtime size (in
>bytes) of an arbitrary object? My problem is that I'm allocating a large
>number of elaborate objects (i.e. where it's tricky to figure out the
>size by hand) and I need to know how much memory they'll cumulatively
>suck up.

>TIA



Tue, 04 Dec 2001 03:00:00 GMT  
 object size
The first way I could think of is to implement your classes in a way that
makes instantiated objects reflect every bit of memory that they are allocated
or that they allocate in some variable. If your objects are that elaborate then
you must find some way to do it recursively.

An other way to accomplish that is to use some low level runtime interface,
that of course you can't find anywhere (although I don't think it is possible
to do that in a generic way, as it is very tricky).

However, you may find a de{*filter*} that does it for you, but I don't know any.

Good luck.

Quote:

> When I'm debugging, is there any way to determine the runtime size (in
> bytes) of an arbitrary object? My problem is that I'm allocating a large
> number of elaborate objects (i.e. where it's tricky to figure out the
> size by hand) and I need to know how much memory they'll cumulatively
> suck up.

> TIA



Sun, 03 Mar 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. object size

2. Getting Object size

3. gcc object size

4. Object Size

5. COM object size is very large

6. Info: MFC object sizes (6K of text)

7. C# Object size

8. Size of generated objects files for VC7

9. Object code sizes

10. finding the memory size of a managed object

11. Object code size in C++

12. Size of object file

 

 
Powered by phpBB® Forum Software