I have this scenario:
the issue is the following:
simplified code for library:
struct TmRecordValue
{
UINT8 RecordValue[128];
};
struct TmRecord{
TmRecordValue RecordValues[2];
};
struct TmStruct
{
UINT32 NumberOfRecords;
TmRecord* Records;
};
void InitializeStruct(TmStruct* pStruct, int pNumberOfRecords)
{
memset(pStruct, 0, sizeof(TmStruct));
pStruct->NumberOfRecords = pNumberOfRecords;
pStruct->Records = new TmRecord[pStruct->NumberOfRecords];
memset(pStruct->Records, 0, sizeof(TmRecord) * pStruct->NumberOfRecords);
}
void AddRecordToStruct(TmStruct* pStruct, int pRecordIndex, char* pFirstValue, char* pSecondValue)
{
strcpy_s(reinterpret_cast<char*>(pStruct->Records[pRecordIndex].RecordValues[0].RecordValue), 128, pFirstValue);
strcpy_s(reinterpret_cast<char*>(pStruct->Records[pRecordIndex].RecordValues[1].RecordValue), 128, pSecondValue);
}
simplified code for program:
TmStruct *struct1 = new TmStruct();
int RecordsQuantity = 100000;
InitializeStruct(struct1, RecordsQuantity);
for (int i = 0; i < RecordsQuantity; i++)
{
AddRecordToStruct(struct1, i, "first", "second");
}
Comments:
Thanks in advance,
Check calling conventions. Make sure you use cdecl
everywhere or stdcall
everywhere.
Because by symptoms it looks like Visual Studio library is cdecl
but Embarcadero program assumes it to be stdcall
, so no stack is deallocated neither by library, nor by caller.