- Home /
How much memory does a pointer use?
The title says it all.
For example a pointer to a class:
MyClass pointer = new MyClass ();
Or a gameObject:
GsmeObject pointer = gameObject;
Thanks in advance.
Answer by Ashkan_gc · Mar 01, 2010 at 05:37 AM
first of all these are references and not pointers. they have some differences. any ways, the size of a reference is so small. it's just an adress. in .NET size of all datatypes are the same in all systems and platforms. i think it's 64 bit in .NET but i am not sure. use the sizeof operator to get it and print it. if you want to calculate the size of an object i should say. all instances of a class share the code section (methods) but the data section (fields and properties) are seporate. the size of each object is the size of all of it's private/public//static variables.
Answer by _Petroz · Dec 01, 2010 at 05:06 AM
Let me provide a little background for those who are interested.
In C/C++ the answer would be: For 32 bit software a pointer is 32 bits (4 bytes) For 64 bit software a pointer is 64 bits (8 bytes)
This is the whole point of 32 vs. 64 bit (pointer size). Most people know that a 64 bit OS will support more memory than a 32 bit OS. The reason is that the biggest number a 32bit value can hold is 2 ^ 32 = 4294967296 = 4 x 1024 x 1024 (4 GB)
So the largest memory address you can 'point' to with a 32bit pointer is 4GB. This prevents the OS from using any memory beyond that, that is where the limitation comes from. In practice you can only have 2 or 3 GB of RAM because some of those memory addresses are reserved for other memory including graphics card memory.
As for pointers/references in mono, it is possible that 32 bit platforms would use 64 bit pointers for portability. It wouldn't surprise me if they shoved some refcount, RTTI data and/or other metadata in there as well. So maybe they're a little bigger, but generally it is safe to consider the size to be negligable.
Answer by Ryan Zec · Mar 01, 2010 at 01:39 AM
Well a pointer is just a memory address and as far as I know is usually just an unsigned int which on most systems is 2 bytes. The object itself however varies as you would need to add up the sizes of all the variables that the objects holds.
Actually most integers nowadays are 32 bits, unless you have something like an application built for executing in ye olde 16 bit mode.
Answer by Kethis Celebes · Mar 01, 2010 at 04:31 AM
Ryan Zec is correct, a pointer is a trivial amount of memory (unless you are using astronomical numbers of them). What it points to can be any amount though.
Answer by Lokesh.du · Mar 02, 2010 at 06:50 AM
i want to know to store a pointer variable how much memory is required
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Changing variables in GUI? 0 Answers
Gun Script Help 2 Answers
How to use Enum? 1 Answer
Array Problem - Error Code BCE0022 2 Answers