I need to get the size of an objet in memory. I have tried:
System.IO.Memor yStream m = new System.IO.Memor yStream();
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er b = new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er();
b.Serialize(m, Obj);
double size = Convert.ToDoubl e(m.Length);
but not everything is serializable. The thing is I want to be able to
take an arbitarty object, (since everything I am attempting to size is
comming out of the cache), and get the size of it. I am wondering if it
not possible to treat it like a stream or a byte array or something like
that so that it is easy to get the size. I don't need any attributes off
of the object, I just need the size. Anyone have any ideas?
-Cam 6 41012
cameron <ca************ ****@appdepot.c om> wrote: I need to get the size of an objet in memory. I have tried:
System.IO.Memor yStream m = new System.IO.Memor yStream();
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er b = new System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er(); b.Serialize(m, Obj); double size = Convert.ToDoubl e(m.Length);
but not everything is serializable. The thing is I want to be able to take an arbitarty object, (since everything I am attempting to size is comming out of the cache), and get the size of it. I am wondering if it not possible to treat it like a stream or a byte array or something like that so that it is easy to get the size. I don't need any attributes off of the object, I just need the size. Anyone have any ideas?
"Size" can be either misleading or meaningless when you consider
reference types. For instance:
public class Foo
{
string x;
public Foo (string x)
{
this.x=x;
}
}
Foo f1 = new Foo ("hello");
Foo f2 = new Foo ("hello");
Now, what is the size of f1 and f2? Combined, it should be double the
size of the Foo class instance itself (probably 12 bytes - an object
header of 8 bytes plus a reference) and the size of the string (16 or
20 bytes, at a guess) - but the size of each of them individually would
be the size of the Foo class instance itself plus the string - so the
whole is greater than the sum of the parts... but if you ignore the
string itself, it becomes meaningless in the other way.
So, what do you *really* mean, and what do you *really* want to try to
measure?
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi cameron,
Serialization won't help. First because it will put more info than you maybe
expect. The stream is goint to be bigger then the object itself is. Second
because serializer (if you don't take any precautios) will serialize any
serializable objects your object references.
IMHO there is no way to get the size of a managed object. Even the size
might not be the same if you run the application on machines with different
configuration and/or different versions of .NET. If not stated otherways CLR
is free to rearange and layout the objects as it sees fit. That means that
you may end up with diffrent padding of the fields and different sizes in
memory.
The only size that you can get is the size on bytes of the unmanaget
equivalent of your type
Marshal.SizeOf( ...)
--
B\rgds
100
"cameron" <ca************ ****@appdepot.c om> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l... I need to get the size of an objet in memory. I have tried:
System.IO.Memor yStream m = new System.IO.Memor yStream();
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er b = new System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er(); b.Serialize(m, Obj); double size = Convert.ToDoubl e(m.Length);
but not everything is serializable. The thing is I want to be able to take an arbitarty object, (since everything I am attempting to size is comming out of the cache), and get the size of it. I am wondering if it not possible to treat it like a stream or a byte array or something like that so that it is easy to get the size. I don't need any attributes off of the object, I just need the size. Anyone have any ideas?
-Cam
Fair enough. The Object is being placed in the Cache - I want to know
how much space is being taken up by that object, (in it's entirity), on
the Heap.
-Cam
Jon Skeet [C# MVP] wrote: cameron <ca************ ****@appdepot.c om> wrote:
I need to get the size of an objet in memory. I have tried:
System.IO.Mem oryStream m = new System.IO.Memor yStream();
System.Runtim e.Serialization .Formatters.Bin ary.BinaryForma tter b = new System.Runtim e.Serialization .Formatters.Bin ary.BinaryForma tter(); b.Serialize(m , Obj); double size = Convert.ToDoubl e(m.Length);
but not everything is serializable. The thing is I want to be able to take an arbitarty object, (since everything I am attempting to size is comming out of the cache), and get the size of it. I am wondering if it not possible to treat it like a stream or a byte array or something like that so that it is easy to get the size. I don't need any attributes off of the object, I just need the size. Anyone have any ideas?
"Size" can be either misleading or meaningless when you consider reference types. For instance:
public class Foo { string x;
public Foo (string x) { this.x=x; } }
Foo f1 = new Foo ("hello"); Foo f2 = new Foo ("hello");
Now, what is the size of f1 and f2? Combined, it should be double the size of the Foo class instance itself (probably 12 bytes - an object header of 8 bytes plus a reference) and the size of the string (16 or 20 bytes, at a guess) - but the size of each of them individually would be the size of the Foo class instance itself plus the string - so the whole is greater than the sum of the parts... but if you ignore the string itself, it becomes meaningless in the other way.
So, what do you *really* mean, and what do you *really* want to try to measure?
cameron <ca************ ****@appdepot.c om> wrote: Fair enough. The Object is being placed in the Cache - I want to know how much space is being taken up by that object, (in it's entirity), on the Heap.
Right - as I said, that really depends on other objects etc. There's no
way of determining it, I'm afraid. If you know more about your objects
- like that the bulk of the size is going to be taken up by a byte
array which you have access to and which won't have duplicate
references within the cache, for instance, you could use the size of
that as a rough indication...
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi cameron,
Thank you for posting in the community!
I think Stoitcho and Jon have explained the reason why you can not get the
managed class instance size.
But I think what you want to do is getting the unmanaged class instance
size, so just as Stoitcho point out, you can use Marshal.SizeOf to returns
the unmanaged size of an object in bytes.
For more information, please refer to: http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemrunt imeinteropservi cesmarshalclass sizeoftopic.asp
=============== =============== ============
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Hi cameron,
Does the community's reply make sense to you?
If you still have anything unclear, please feel free to post, we will help
you.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard |
last post by:
Hi all,
I am looking for some help on understanding the overhead associated with
object creation in Java.
I am writing an application where I have written a class to encapsulate some
text data.
The class is contains these private variables:
|
by: cwizard |
last post by:
I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not an object... the
function is like so:
function calc_total()
{
var x,i,base,margin,total,newmargin,newtotal;
base = document.frmKitAmount.txtTotalKitValue.value;
margin = document.frmKitAmount.margin.value/100;
|
by: Virendra Verma |
last post by:
This sounds weird, but I am looking for separate behaviors for
destruction of a const and non-const object.
I am trying to develop a smart/auto pointer class for writing objects
to disk implicitly. The destructor of this class saves the object to
the disk if it is dirty. The problem comes in the following scenario
when a function returns an uncommitted pointer class because same
copies will be committed as two separate objects on disk....
|
by: Andrew Au |
last post by:
Dear all,
I am trying to write a piece of software that use Object Oriented design
and implement it with C, I did the following
== In Object.h ==
typedef struct ObjectStructure* Object;
Object object_create();
int object_getIntegerAttribute(Object object);
|
by: Phil Jones |
last post by:
Is there a way to determine the size (number of bytes) of an object?
I figure this can be done by serializing the object to disk and measuring
the file size - but I definately don't want to do this for performance
reasons. I'm hoping there is some Framework class that dishes up the
in-memory size of an object.
Is there???
Thanks everyone....
| |
by: al.cpwn |
last post by:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"
|
by: Scirious |
last post by:
People, how can I know how big an object is? I mean, I have an object the
collects data from a stream and when it grows to an especific size I need
to create a new object to continue collecting the data and send the other
one to a thread that records it's content to the disk.
How do I do such thing?
TIA,
Scirious.
|
by: =?Utf-8?B?SkhhbGV5?= |
last post by:
Our system is:
IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram
Windows Server 2003 SP2
IIS 6.0
SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server)
Windows Server 2003 SP2
SQL Server 2000
We are having some problems with a website we are developing, and had some
|
by: tonytech08 |
last post by:
What I like about the C++ object model: that the data portion of the
class
IS the object (dereferencing an object gets you the data of a POD
object).
What I don't like about the C++ object model: that most OO features
are not
available for class object design without loss of POD-ness.
So, I'm more than leaning toward "bad" because of the limitations and
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |