473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2509
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
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
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
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
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
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
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
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
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
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
by: vineesh vs | last post by:
#include<stdio.h> #include<stdlib.h> int **transpose(int **x,int m,int n);
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.