Question on code from tutorial

Jun 27, 2009 at 12:58am
The code on page 90 of the tutorial (the pdf version) has contained in the constructor the two lines

width = new int;
height = new int;

I don't understand what this is and why it is needed. Don't think "new" was talked about yet in the tutorial. Thanks.

Last edited on Jun 27, 2009 at 12:59am
Jun 27, 2009 at 1:02am
Page 74.
Jun 27, 2009 at 1:18am
oh that is right, "new" is for dynamic memory, thanks.
Jun 27, 2009 at 2:20am
closed account (S6k9GNh0)
new simply allocates enough memory for sizeof(int);

Because there is no sequence in where the memory is located, it passes back a handle to the randomly allocated memory. You can then access your data by using the dereference(*). This is effecient for almost all large classes, large arrays, and almost everything placed inside of a buffer (audio decoding, mesh loading, useful for games).
Topic archived. No new replies allowed.