473,505 Members | 16,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reuse allocated memory

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.

Is there any functions or api's or your idea available? Please let me
know.

-Thanks in advance
santhakumar

Nov 14 '05 #1
3 2521
Santh <bs*****@gmail.com> wrote:
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.
Sorry, but that sentences don't make sense. First of all, what is a
"safearray pointer"? And what means "copy that data to another poin-
ter"? Do you mean "copy to a location a different pointer points to"?
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.
Why then copy at all? Just make your variable (a pointer, I guess) point
to where "safearray" is or what it points to (whatever it is).
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.
Is "safearray" an array or a pointer? And means "can be cleared" that
you e.g. zero out all elements of an array or that you set a pointer
to NULL or deallocate memory it points to?
Is there any functions or api's or your idea available? Please let me
know.


Sorry, but please try to rephrase this a bit, perhaps with some
code for illustration, I find it nearly incomprehensible.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #2
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

Nov 14 '05 #3
Santh wrote:

This is my sample code for your reference. /////////////code////////////////////////////
HRESULT CWave::CopySafeArrayData(SAFEARRAY** psa)
{
///.....


news:comp.lang.c++

--
pete
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
399
by: Santh | last post by:
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...
3
3602
by: Tony Johansson | last post by:
Hello Experts!! When you instansiate varaibles(object) you can do so in four different scops which are. Within a block which is called Local or block scope . Within a function which is called...
7
2344
by: serikas | last post by:
Is there a way to get aligned dynamically allocated memory? (provided that the requested memory size is a power of 2.) For example, if I request 128 bytes of memory, can I implement an allocator...
34
33058
by: Andrew | last post by:
Is there anyway to test if a pointer points to allocated memory or not? For example if I have a pointer such as char *p is there a standard way to test whether an assignment such as the following...
7
1665
by: Curley Q. | last post by:
for(;;) { c = a * b; c %= 100000; printf("%9d", c); d = int2str(c); left = midstr(d, 0, 3); right = midstr(d, strlen(d)-3, 3); free(d); a = atoi(left);
3
6880
by: mandark_br | last post by:
I have a function that returns a int pointer to a allocated memory. How I know the size of this allocated memory? Compiler = gcc Ex.: int main(void) {
2
2052
by: lovecreatesbeauty | last post by:
Hello experts, When I allocate memory use malloc() and forget to call a corresponding free(), does this allocated memory lose forever after program exits (Can i regard it same as process...
74
4589
by: ballpointpenthief | last post by:
If I have malloc()'ed a pointer and want to read from it as if it were an array, I need to know that I won't be reading past the last index. If this is a pointer to a pointer, a common technique...
26
3022
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
4
3496
by: vineesh vs | last post by:
#include<stdio.h> #include<stdlib.h> int **transpose(int **x,int m,int n);
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.