Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TowerOfBricks · Feb 28, 2010 at 11:45 PM · variablememory

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image by0log1c · Jan 12, 2012 at 05:28 AM 0
Share

Well it definitely interested me!

avatar image
1

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ricardo · Mar 01, 2010 at 08:01 AM 1
Share

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

avatar image Minthos · Apr 07, 2011 at 09:14 AM 1
Share

or 64 bits (8 bytes).

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges