#define ALIGNBUF(Length) Length % ALIGNSIZE ? \
Length + ALIGNSIZE - (Length % ALIGNSIZE) : Length
short NumCols;
long * ColLenArray, * OffsetArray;
ColLenArray = new long(NumCols * sizeof(long));
OffsetArray = new long(NumCols * sizeof(long));
// THIS CODE SHOULD NOT BE NEEDED TO UNDERSTAND THE PROBLEM
// BUT I HAVE INCLUDED IT JUST IN CASE
////////////////////////////////////////////////////////////
SQLColAttribute(hstmt, ((SQLUSMALLINT) i)+1, SQL_DESC_OCTET_LENGTH, NULL, 0, NULL, &ColLenArray[i]);
ColLenArray[i] = ALIGNBUF(ColLenArray[i]);
if (i)
OffsetArray[i] = OffsetArray[i-1]+ColLenArray[i-1]+ALIGNBUF(sizeof(SQLINTEGER));
////////////////////////////////////////////////////////////
void **DataPtr = new void*[OffsetArray[NumCols - 1] + ColLenArray[NumCols - 1] + ALIGNBUF(sizeof(long))];
delete []DataPtr;
Don’t think it can be done, have tried every way imaginable.
This code works, as in the program runs, I just can’t deallocate the memory. Every time this code is called(not all code included as it isn’t relevant) the memory gets bigger. I think that deletion is not happening properly and that the void * keeps growing.
I have also changed some of the code above based on recommendations here, but as this code is, the memory keeps growing.
You should try avoid mixing
void*andnew. In C++ actually,newis meant to automatically determine the type of the pointer; then why should not use it. At least you can usechar*, if you are simply dealing with raw bytes.Other point is
new void*[SIZE]allocatesvoid**. So you should change the declaration tovoid **DataPtr. Remove typecasting ahead ofnew. You can nowdelete[] DataPtr;.Edit:
The code have some problems, the variables should be declared like below:
when you declare those variables as,
new long(); it will simply initialize the value and assign a pointer to singlelong.The memory corruption happens because, you are using
ColLenArray[i], which is accessing wrong memory. Since you are going to use above variables as arrays, it should benew long[]. Then memory corruption will not happen. After usage, you shoulddelete[]them.