S
Santh
Hi,
I have a bulk of data available in safearray pointer. I want to
copy that data to another pointer. I tried using malloc for new
variable and memcopy. But due to virtual memory restrictions the
allocation failed. This is because the system memory can not allocate
another volume of memory.
My requirement is , without allocating the new memory, how can I copy
the data from safe array to my variable. Since after copying I dont
need the safearray data anyway. so during memcopy process itself it can
be cleared. So that with less free memory i should be able to copy the
whole content from safe array to my long pointer variable. Or even I
can use the same data in safearray memory to my new pointer and
safearray poiner can be cleared.
This is my sample code for your reference. if u can help, more
appriciated.
The malloc statement fails because there is not enough memory to
allocate. But my thought is, the safearray holding a data can be copied
to my m_Dataptr and cleared with the help of available memory. Hope you
got my requirement.
/////////////code////////////////////////////
HRESULT CWave::CopySafeArrayData(SAFEARRAY** psa)
{
///.....
if (!*psa)
return S_OK;
// check the number of dimensions
if ((*psa)->cDims != 1)
{
ATLTRACE("CWave::CopySafeArrayData() Error :
E_DSPALGS_INVALID_ARGS_TYPE");
return E_DSPALGS_INVALID_ARGS_TYPE;
}
// check the number of elements
long num = (*psa)->rgsabound[0].cElements;
if (num == 0)
return S_OK;
long* pdata;
HRESULT hr = SafeArrayAccessData(*psa, (void**)&pdata);
if (FAILED(hr)) {
return hr;
}
m_dataptr = malloc(num*m_datatypesize);
if (!m_dataptr)
{
::MessageBox(0, "Mem Not allocated", "error",MB_OK);
ATLTRACE("CDspWave::CopySafeArrayData() Error :
E_DSPALGS_FAILED_ALLOCATE_MEMORY");
SafeArrayUnaccessData(*psa);
return E_DSPALGS_FAILED_ALLOCATE_MEMORY;
}
memcpy(m_dataptr, pdata, num*m_datatypesize);
SafeArrayUnaccessData(*psa);
//....
//....
}
//////////////End of
code///////////////////////////////////////////////////
-Thanks
Santhakumar
I have a bulk of data available in safearray pointer. I want to
copy that data to another pointer. I tried using malloc for new
variable and memcopy. But due to virtual memory restrictions the
allocation failed. This is because the system memory can not allocate
another volume of memory.
My requirement is , without allocating the new memory, how can I copy
the data from safe array to my variable. Since after copying I dont
need the safearray data anyway. so during memcopy process itself it can
be cleared. So that with less free memory i should be able to copy the
whole content from safe array to my long pointer variable. Or even I
can use the same data in safearray memory to my new pointer and
safearray poiner can be cleared.
This is my sample code for your reference. if u can help, more
appriciated.
The malloc statement fails because there is not enough memory to
allocate. But my thought is, the safearray holding a data can be copied
to my m_Dataptr and cleared with the help of available memory. Hope you
got my requirement.
/////////////code////////////////////////////
HRESULT CWave::CopySafeArrayData(SAFEARRAY** psa)
{
///.....
if (!*psa)
return S_OK;
// check the number of dimensions
if ((*psa)->cDims != 1)
{
ATLTRACE("CWave::CopySafeArrayData() Error :
E_DSPALGS_INVALID_ARGS_TYPE");
return E_DSPALGS_INVALID_ARGS_TYPE;
}
// check the number of elements
long num = (*psa)->rgsabound[0].cElements;
if (num == 0)
return S_OK;
long* pdata;
HRESULT hr = SafeArrayAccessData(*psa, (void**)&pdata);
if (FAILED(hr)) {
return hr;
}
m_dataptr = malloc(num*m_datatypesize);
if (!m_dataptr)
{
::MessageBox(0, "Mem Not allocated", "error",MB_OK);
ATLTRACE("CDspWave::CopySafeArrayData() Error :
E_DSPALGS_FAILED_ALLOCATE_MEMORY");
SafeArrayUnaccessData(*psa);
return E_DSPALGS_FAILED_ALLOCATE_MEMORY;
}
memcpy(m_dataptr, pdata, num*m_datatypesize);
SafeArrayUnaccessData(*psa);
//....
//....
}
//////////////End of
code///////////////////////////////////////////////////
-Thanks
Santhakumar