Thank you.
Well, so I can do something like (related to above code):
1 2 3 4 5
|
char *pszData = malloc(sizeof(char *) * (iLength + 1));
if(pszData) {
memcpy(szData, szValue, iLength + 1);
m_pData = (void *)pszData;
}
|
Then after:
1 2 3 4
|
char *pszData = (void *)m_pData;
if(pszData) {
delete[] pszData;
}
|
Or (in case I have created an int):
1 2 3 4
|
int *pData = (int *)m_pData;
if(pData) {
delete[] pData;
}
|
And everything is safe? Well, for sure it's just a matter or dealing with the right address.
But I was just wondering with the delete[] operator, if this will delete the whole data size in bytes without having the need of casting it back as you said. And also if I needed the use of the basic "delete" (without brackets) according to the size I had allocated.
And also maybe if using another operator/function than "delete" will be more appropriated for such need.
I have also a member that stores the data type, so I could do some "switch/checks" for such case, not a problem for me. But will a template with the type could work as alternative?
Or a more direct alternative, because doing something like:
1 2 3 4 5 6 7 8 9
|
if(m_iDataType == DT_Integer) {
int *iData = (int *)m_pData;
delete[] iData;
}
else if(m_iDataType == DT_Float) {
float *flData = (float *)m_pData;
delete[] flData;
}
etc.
|
Look like slighly annoying/trivial!
But if there is no other reliable method for my needs, I'll stick to it.
I have also a question, I have two modules, one which has an API of functions at through a "table" (a struct with the functions inside and their format, and a global variable matching to the function struct, so I call like "g_pFunctionsList->pfnMyFunction1(params...)").
And what is the performance difference between calling such function from an API available externally (other binary), and directly calling it from the current module (in case I implement it inside the current module).
I'm guessing it's much better when we call a function in its own binary (at least by logic due to how the programming things works), but since it's a matter of "calling an address" I'm wondering the level of performance difference for this case.