Advertisement

Tutorial #4 (MD2) : mistake using 'new'

Started by December 19, 2001 06:29 AM
0 comments, last by Muhammad Haggag 23 years, 2 months ago
quote:
From the tutorial Say we want to load the glCommands variable, well, here is how we''d go about doing it:
glCommands= new long [header.numGlCommands*sizeof(long)]; 

Demonstration code :
Type *pMem = new Type[nItems]; 
In this piece of code, ''new'' allocates memory enough for nItems of type Type . That means it is equivalent to a such a call to malloc :
Type *pMem = (Type*) malloc(nItems * sizeof(Type)); 
Thus, NeHe''s code allocates n times the memory needed for the glCommands (where n is the sizeof(long)). This means there''s some wasted space. I believe it should be :
glCommands = new long[header.numGlCommands]; 
It works fine this way. Thanks (I''m sorry if someone said this before, I just made a search on the board and didn''t find any relevant threads)

No threads about the subject, but I recieved numerous e-mails about the subject, and I believe I fixed the actual tutorial''s code (or at least, I fixed the code in future tuts ).

------------------------------
Trent (ShiningKnight)
E-mail me
"Whoso is a man, is a nonconformist"
--Ralph Waldo Emerson

This topic is closed to new replies.

Advertisement