Skip to main content
gamedev.net
🔒 Locked

new vs. malloc()

Started by untalkative_monkey Jan 3, 2002 at 10:21 AM 3 replies 700+ views
Original Post
untalkative_monkey
untalkative_monkey
Ok, I''m pretty new to programming so I try to be mostly a c++ person... but I realized something. Is it possible to convert a malloc statement like this, to a new statement? char *buffer; buffer = malloc(width * height * 2); How would you pull that off? ...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
untalkative_monkey
untalkative_monkey
Oh, I can''t believe i didn''t think of that....
*sigh*

...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
krez
krez
with malloc you have to account for the size of the type (i think sizeof(char)==1 so it doesn''t matter in this example). but, for something else:

int v*;
// c way
v* = malloc(width * height * sizeof(int));
// c++ way
v* = new (width * height);

with new, you just worry about the dimensions.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

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

Sign in to reply to this topic.