|
As we can reallocate memory to the memory which was allocated withe calloc() function,using realloc()
How can we reallocate memeory for the memory which was allocated using new operator.
KIRAN PINJARLA
|
|
|
|
|
no way with new/delete.
BTW, what are you trying to achieve ?
if you're coding a container like a linked list, have you thought to use the STL ?
|
|
|
|
|
It doesn't work that way in C++. You have to write your own function to reallocate memory that's allocated with new, or you can use STL. (ie, vector)
std::vector<>::resize()
|
|
|
|
|
Thank You.
i want a to create a unsigned char * buffer whose size will be growing at runtime. For that i want to use vector<>.
how to use it for this?
first i want a BYTE* buffer[1000]; and at runtime everytime its size will be increased to 1000 and buffer of size 1000 should be appended to that buffer.
how this can be done using vector<>.
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: first i want a BYTE* buffer[1000]; and at runtime everytime its size will be increased to 1000 and buffer of size 1000 should be appended to that buffer.
how this can be done using vector<>.
Is this what you want? Not sure if that's what you're asking though.
<br />
const int DEFAULT_SIZE = 1000;<br />
vector< unsigned char * > buffer(DEFAULT_SIZE);<br />
<br />
cout << "Before resize: " << buffer.size() << endl;<br />
<br />
buffer.resize(DEFAULT_SIZE + 1000);<br />
<br />
cout << "After resize: " << buffer.size() << endl;<br />
Before resize: 1000
After resize: 2000
|
|
|
|
|
It's also worth noting that if you need the pointer to the beginning of your buffer, you can use
BYTE* pBuffer = &buffer[0]; // address of the first element of the vec
|
|
|
|
|
Link2006 wrote:
buffer.resize(DEFAULT_SIZE + 1000);
cout << "After resize: " << buffer.size() << endl;
sorry, but little problem.. you cannot get the string as a whole.. it every charcter has it unique character...
better you have unsigned char instead it's pointer!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
Then I would write my own append function instead of using vector.
|
|
|
|
|
Link2006 wrote:Then I would write my own append function instead of using vector.
Instead of that you can write your own string function.. which i believe much easier to write!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
kiran.pinjarla wrote: How can we reallocate memeory for the memory which was allocated using new operator.
You can't, and for good reason.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi yaar,
I have an problem "Automation Error " with MTS COM+ while creating an package using VB. Following is the code snippet.
CompUtil.InstallComponent fld.Path & "\" & File1.Name, "", ""
please give me a solution ASAP.
You only have to do a very few things right in your life so long as you don't do too many things wrong.
Vivek.S
|
|
|
|
|
I am very much confused as anyone else who read your post.
BTW, heres some help which you didn't ask us, but which you are in need of.
vivek.s.vivek wrote: I have an problem......creating an package
Where to use AN[^]
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Hi yaar,
I have an problem with MTS COM+ while creating an
package using VB. Following is the snippet.
CompUtil.InstallComponent fld.Path & "\" & File1.Name, "", ""
please give me a solution
You only have to do a very few things right in your life so long as you don't do too many things wrong.
Vivek.S
|
|
|
|
|
Hi
How can I populate my treeView with data from access database
thanks
|
|
|
|
|
This[^] msdn sample does something similar...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi All,
Say if i'm allocating memory using 'new' operator.
Without deleting the alloacated memory, my application exits.
Now is it a memory leak??
I hope its not.. comments please ..
Do your Duty and Don't expect the Result
|
|
|
|
|
it is. sometimes, the operating system can clean the memory you forgot the free, but sometimes, it won't... thus the memory leak.
|
|
|
|
|
Unaltered new operators will never leak memory after the application exits. Maybe if you've overriden a new operator to allocate shared memory or something similar.
--
Larva-Tested, Pupa-Approved
|
|
|
|
|
Parthi_Appu wrote: Say if i'm allocating memory using 'new' operator.
Without deleting the alloacated memory, my application exits.
It is a memory leak. Every new should be followed by a delete and every new [] should be followed by delete [] .
Parthi_Appu wrote: I hope its not.. comments please ..
If only...
|
|
|
|
|
Parthi_Appu wrote: Memory Leak!!!
Here[^]is an article that would clear most of your doubts on memory leak.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: Here[^]is an article that would clear most of your doubts on memory leak.
In general, but nothing specific to Windows.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
_AnShUmAn_ wrote: Here[^]is an article that would clear most of your doubts on memory leak.
he he he .. making use of google .. you are great programmer!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|
|
ThatsAlok wrote: making use of google
It's my say that I don't know it, I find it, and then learn it. How do you opine on this. Is it good or bad?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
_AnShUmAn_ wrote: It's my say that I don't know it, I find it, and then learn it. How do you opine on this. Is it good or bad?
no doubt WikiPedia Article is nice... plus Google is only weapon apart from programming site programmer can have
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Parthi_Appu wrote: Now is it a memory leak??
yes.. try running bound checker or run you application in debug mode!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief And you
|
|
|
|