raylopez99 <ra********@yahoo.comwrote:
Marshal..::.SizeOf Method (Object) and sizeof() do not exist for
objects in a managed language, right?
I was trying to find how much memory is taken up by an array of ints,
and I could not use sizeof or Marshal.SizeOf(), since apparently these
functions are for unmanaged code.
With references and managed languages, what do you use to figure this
out?
The thing is, there's no easy answer because of the way objects
reference each other. There are two things to consider:
1) The object's direct footprint on the heap (or the footprint of a
value type, wherever it's stored).
2) The memory which is taken up by that object *and other objects it
references* (etc, recursively). This will give you some idea of how
much memory could be reclaimed if the object became eligible for
garbage collection - but only if *other* (ineligible) objects didn't
reference some of the same objects.
For an array of ints, however, it's basically the size*4 + some
overhead (about 12 bytes at a guess, but it could be a bit more - not a
lot).
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com