Name: Anonymous 2010-10-19 17:04
Fucking void pointers, how do they work
is it possible to deallocate a pointer casted void to an array consisting of anything besides primitive types, aka objects allocated on the heap?
ex:
Obj *array = new Obj[5];
void *cocks = (void *) array;
free(cocks);
or
Array *morecocks = (Array*)cocks;
delete [] morecocks;
on the same note, what is wrong with this code, dont say bad style i'll fucking kill you, that's not the point of it
dumbed down version:
size_t Size = 2;
Balls<int> *atest = new Balls<int>[Size];
void *vtest = (void *)atest;
ASS( vtest, sizeof(Balls<int>), Size, 5 );
delete [] atest;
atest = (Balls<int> *)vtest;
ASS does a manual realloc and index copy with last arg as new size (tested), and Balls has an <int> array and some other member variables
for( int counter = 0; counter < 2*sizeof(Balls<int>); ++counter )
std::cout << int(((char*)((void*)atest))[counter]) << ' ';
returns the same values before and after (on the stack), but any atest.array[anything] now returns garbage
is it possible to deallocate a pointer casted void to an array consisting of anything besides primitive types, aka objects allocated on the heap?
ex:
Obj *array = new Obj[5];
void *cocks = (void *) array;
free(cocks);
or
Array *morecocks = (Array*)cocks;
delete [] morecocks;
on the same note, what is wrong with this code, dont say bad style i'll fucking kill you, that's not the point of it
dumbed down version:
size_t Size = 2;
Balls<int> *atest = new Balls<int>[Size];
void *vtest = (void *)atest;
ASS( vtest, sizeof(Balls<int>), Size, 5 );
delete [] atest;
atest = (Balls<int> *)vtest;
ASS does a manual realloc and index copy with last arg as new size (tested), and Balls has an <int> array and some other member variables
for( int counter = 0; counter < 2*sizeof(Balls<int>); ++counter )
std::cout << int(((char*)((void*)atest))[counter]) << ' ';
returns the same values before and after (on the stack), but any atest.array[anything] now returns garbage