Skip to main content
gamedev.net
🔒 Locked

Malloc()

Started by lotana Jul 3, 2004 at 10:40 PM 3 replies 400+ views
Original Post
lotana
lotana
While going through a source code written in C, I had came across a usage of a malloc() function, which I had never encountered before. The general layout of it is as follows: int* variable1; variable1 = (int *) malloc(variable2 * variable3) My questions are: -What does this statement does? -How would I write this using the new keyword in C++? Thank you.
NLDEV
NLDEV
Quote:
Original post by lotana
While going through a source code written in C, I had came across a usage of a malloc() function, which I had never encountered before. The general layout of it is as follows:

int* variable1;

variable1 = (int *) malloc(variable2 * variable3)

My questions are:

-What does this statement does?
-How would I write this using the new keyword in C++?

Thank you.


As far as I can tell, it is allocating a block of memory of size variable2 * variable3. In C++ you'd do something like this:

int *variable1 = new int[ variable2 * variable3 ];


[edit: AP beat me to it]
lotana
lotana
Thank you very much.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.