|
the allocated memory is using in endless loop, then i don't free it.
do i allocate mamory (to call GlobalAlloc) in begin of loop then free it end of loop?
Zo.Naderi-Iran
|
|
|
|
|
dude, do you think the memory is infinite ?
all you'll get is an error saying that you cannot allocate much memory...
moreover, if you don't free the memory you allocate, you're going into leaks, obviously.
|
|
|
|
|
what do i do????
i create a thread, and this thread has an endless loop. in this loop i call api functions , they needs memory.
do i allocate mamory (to call GlobalAlloc) in begin of loop then free it end of loop?
Zo.Naderi-Iran
|
|
|
|
|
all depends what you really need to do, but you seem to have a serious design problem.
can you post a relevant piece of code ?
|
|
|
|
|
my code is secret... thank you
maybe problem for my exe has other cause.
anyhow if you can, you help me
thank you
-- modified at 7:24 Tuesday 27th March, 2007
Zo.Naderi-Iran
|
|
|
|
|
i don't ask you a part of your secret code... i want relevant information so that i can understand the problem, and help you.
a relevant piece of code is not a entiere copy/paste of your cpp file. i want you to show us a small function which can reproduce the problem.
and if you can't, then at least provide full comments in your question, because i doubt anybody can help you with what you gave here
|
|
|
|
|
For example: i call EnumProcesses function in endless loop (in thread),
first parameter of this function is a Pointer to an array that receives the list of process identifiers.
i call GlobalAlloc function to allocate memory with 1024 bytes or more for size (befor endless loop), then i send pointer to this memory (return value of GlobalAlloc) to EnumProcesses function :
__asm<br />
{<br />
mov ecx, 4096
push ecx<br />
push GMEM_FIXED<br />
call GlobalAlloc
mov dword ptr[ebp + 0x48], eax
<br />
EndlessLoop:<br />
<br />
lea ecx,dword ptr[ebp + 0x49]
push ecx<br />
mov ecx, 4096<br />
push ecx<br />
mov edx,[ebp + 0x48]<br />
push edx<br />
call EnumProcesses
<br />
<br />
<br />
<br />
jmp EndlessLoop<br />
<br />
}<br />
i add a code section to an exe. this section creates thread white endless loop. all of this codes should be assembly language
Zo.Naderi-Iran
|
|
|
|
|
sorry, i talk C++, not asm.
so, as i ***still*** don't know what you want to achieve with this, I can't help you much
|
|
|
|
|
anyhow, thank you
Zo.Naderi-Iran
|
|
|
|
|
|
That's really strange... everywhere you write to me, you answer with an agressive speaking, and i get a low vote.
do you have any problem understanding what CP is for ?
if you roam here not to help anyone but to annoying people who try to help other, i really don't understand what you're here for
|
|
|
|
|
DavidCrow answered your question but looking at your code, you're not allocating memory in the
loop so what are you worried about?
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
zoncpp25 wrote: do i allocate mamory (to call GlobalAlloc) in begin of loop then free it end of loop?
Yes, assuming you know how much you need before the loop starts. If not, you have no choice but to do it in the loop itself.
An alternative is to figure out a worst-case scenario (e.g., 2000 * sizeof(DWORD) ) and allocate for that. While it will likely be too much most of the time, that's a whole lot cheaper (from the Memory Manager) than a ton of smaller requests.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
if i allocate memory first of loop, for example with 256 bytes in size.
then i use 128 bytes of this size, in the loop.
when i free memory end of loop, is freed memory all of the 256 bytes? or the 128 bytes?
nonce, i test "allocate & free" in the loop itself.
then i inform you the result.
thank you
Zo.Naderi-Iran
|
|
|
|
|
zon_cpp wrote: when i free memory end of loop, is freed memory all of the 256 bytes?
Yes.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all,
I have the following structure and piece of code:
typedef struct
#ifdef SAPonOS400
RFC_ERROR_INFO_EX
#endif
{
RFC_ERROR_GROUP group;
RFC_CHAR key[33];
RFC_CHAR message[513];
}
RFC_ERROR_INFO_EX;
RFC_ERROR_INFO_EX * error_info;
RfcLastErrorEx(error_info);
But then I receive this error:
Run-Time Check Failure #3 - The variable 'error_info' is being used without
being defined.
I know what it means but, don't know how to fix it, please help.
Many thanx
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
what about this :
RFC_ERROR_INFO_EX* error_info <code>= NULL</code>;
|
|
|
|
|
Wont work ...
Error:
Unhandled exception at 0x77c47631 in RFC Testing App.exe: 0xC0000005: Access violation writing location 0x00000000.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
|
Programm3r wrote: RFC_ERROR_INFO_EX * error_info;RfcLastErrorEx(error_info);
Modify this to,
RFC_ERROR_INFO_EX error_info;
RfcLastErrorEx(&error_info);
|
|
|
|
|
|
Isn't this answered here[^] ?
|
|
|
|
|
Yes it would seem to be, but you and me, properly posted the thread at the same time, it took me a couple of seconds to realize my mistake. So when i posted my thread there was no response.
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: So when i posted my thread there was no response.
It happens to me lot of times , while posting replies. So, usually, I do refresh forum page in separate browser window, before finally posting it. Its very likely, while you type your post, somebody post same/simlar answer.
|
|
|
|
|