   dynamic allocation question
  i set a pointer, lets say fBMP *bmp;i am using this by dynamically allocating using new at the start of my program, and i use it multiple times to read in several bitmaps. bmp->read(file);i was wondering if this is good practice or not.would it be valid to create a new object and delete it after loading a bmp and then creating another new one followed by a delete for every single bmp?als, should i have to reset/clear any members of fBMP before calling bmp->Read() again???i hope my questions are clear.  
quote:i am using this by dynamically allocating using new at the start of my program, and i use it multiple times to read in several bitmaps. bmp->read(file);i was wondering if this is good practice or not.would it be valid to create a new object and delete it after loading a bmp and then creating another new one followed by a delete for every single bmp?  That''s somewhat implementation-dependant.  If your program only uses one bitmap at a time, and all you have is a single pointer, than unless your bitmap class is designed to handle more than one bitmap (which I assume it isn''t), or your pointer will be to an array of objects, then you should use new and delete each time.  Another alternative is to have an Unload function for your class so you don''t have to allocate the memory each time for the actual bitmap object, but rather unload the image and let the class handle the details.quote:als, should i have to reset/clear any members of fBMP before calling bmp->Read() again???  You tell me   If you have a image data buffer allocated inside the class that stores the actual image bytes, then you''d want to free that before loading another image.  Anything else bitmap-dependant that''s dynamically located inside the object should also be released.  Regular variables (such as width and height) that are just overwritten when a new image is loaded don''t need to be reset, because they''re overwritten.Other than that, you don''t give us much information to work with.  ;  ok.my main function in fBMP is Read(), this function simply reads in a bmp file using FILE to fopen() and then fread() data, then it fclose() the file.all bitmap info such as the bitmap header is stored at private class members.question:if i read multiple bitmaps consecutively, how would that affect anything at all since im using one instance of fBMP as a means of using the fBMP->Read() funcion?  nothing else it going on.;  using new and delete repeatedly is only bad mainly in situations where the bitmap loading is done concurrently with other things. example: loading bitmap while rendering is going on. This case, the new and delete will affect performance for a realtime application.but in the case where its done during no critical sections or even done a limited number of times, its quite ok to use the new and delete.also, if u''re sure that a sequence of loads will access images of similar size e.g. 256x256 24bit BMPs, then reusing the already allocated memory pool rather than delete and new will be good. However, if the image sizes vary then this is not viable coz the pool may either be too small or too large to hold the new image data.  