Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vangelis

The way memory is allocated...

This topic is 5304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I allocate memory as such...
int num1 = new int(1);
int num2 = new int(5);
int num3 = new int(8);
 
Is this memory guaranteed to be allocated in a row, as in an array? I''m trying to figure out pointer arithmetic and I''m wondering if this is what''s going wrong, or my pointer arithmetic.

Share this post


Link to post
Share on other sites
Advertisement
The addresses returned by each new expression will probably not be contiguous. If you want an array use new int[3].

Share this post


Link to post
Share on other sites
Different languages, compilers, computers and OS''s will do memory allocations in different ways. The best would be to always assume that you don''t know how it is allocated .

If you want seperate arrays in continuous memory, allocate a single array like SiCrane suggested, and then use either pointers or aliases to access three seperate arrays inside that memory space.

Regards,
ZX

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!