x


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.

more ▼

asked Feb 28 '10 at 11:45 PM

TowerOfBricks gravatar image

TowerOfBricks
3.2k 17 25 50

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

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.

more ▼

answered Mar 01 '10 at 05:37 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Dec 01 '10 at 05:06 AM

_Petroz gravatar image

_Petroz
3.5k 27 34 57

Well it definitely interested me!

Jan 12 '12 at 05:28 AM by0log1c
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 01 '10 at 01:39 AM

Ryan Zec gravatar image

Ryan Zec
162 3 2 6

Actually most integers nowadays are 32 bits, unless you have something like an application built for executing in ye olde 16 bit mode.

Mar 01 '10 at 08:01 AM Ricardo

or 64 bits (8 bytes).

Apr 07 '11 at 09:14 AM Minthos
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Mar 01 '10 at 04:31 AM

Kethis Celebes gravatar image

Kethis Celebes
149 8 9 18

(comments are locked)
10|3000 characters needed characters left

i want to know to store a pointer variable how much memory is required

more ▼

answered Mar 02 '10 at 06:50 AM

Lokesh gravatar image

Lokesh
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5069
x819
x326

asked: Feb 28 '10 at 11:45 PM

Seen: 6024 times

Last Updated: Jan 12 '12 at 05:28 AM