Pretty much a simple question, but I wanted to confirm what I think I understood from reading elsewhere:
Goal: To allocate some memory as a char*, read in some binary data, re-interpret it as a float* and then free the memory.
My code looks like:
Is the cast back to char* necessary on the red line (or could I have validly left it as float*)? Would it be different if I had written char * tmp = (char*)malloc(sizeof(char)*1000); on the blue line (and correspondingly used free (char*)floatData on the red line?Code:void someFunction(float* &result) { char * tmp = new char[1000]; //...Fill the char buffer here... result = (float*)tmp; //Reinterpret binary data as floats } main(void) { float * floatData; someFunction(floatData); //Do something delete[] (char*)floatData; //Release the memory }
Thanks for any guidance you might have.


Reply With Quote
Bookmarks