new vs. malloc()
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...
char *buffer;
buffer = new char[width * height * 2];
and on the other end...
delete []buffer;
buffer = new char[width * height * 2];
and on the other end...
delete []buffer;
Oh, I can''t believe i didn''t think of that....
*sigh*
...go on and live with no regrets, you only have one life...
*sigh*
...go on and live with no regrets, you only have one life...
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:
with new, you just worry about the dimensions.
--- krez (krezisback@aol.com)
int v*;// c wayv* = malloc(width * height * sizeof(int));// c++ wayv* = new (width * height);
with new, you just worry about the dimensions.
--- krez (krezisback@aol.com)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement