Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > free and coreleft calls

Reply
Thread Tools

free and coreleft calls

 
 
Britt Hibbert
Guest
Posts: n/a
 
      08-20-2003
Hi all

I am working on a 16 bit DOS program, and using Borland to compile my
program.


As a debugging step I have put in the
long coresize = coreleft();
printf("Core left in bytes %ld\n", coresize);
lines of code every time I calloc and free memory. The structs that I
am dynamically allocating and freeing are stored in a linked list, and
I have stepped through the memory freeing code with the TD.exe DOS
debugger. When a node in the linked list is removed, the step through
with the DOS debugger shows me that pointers are being redirected
property etc, and that the pointer passed to free points to the
correct memory location. However, the subsequent call to coreleft does
not report this extra memory after it has been freed.

Subsequent calls to calloc result in different reports from coreleft -
at times after I call calloc, the reported coreleft() value does not
change - I assume this is because the calloc received a pointer to the
memory that was earlier freed but not reported freed by coreleft().
However, at other times, the coreleft value after the calloc IS
smaller, as a result it looks like my program is leaking memory.
However, as I have said, I have stepped through the code with a
debugger numerous times to ensure that pointers were redirected
properly and that the correct pointer was passed to free()

any ideas on what is going on? I am wondering if coreleft is not
reporting the freed memory or if I am doing something wrong.

thanks
Britt Hibbert
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-20-2003
Britt Hibbert wrote:
>
> Hi all
>
> I am working on a 16 bit DOS program, and using Borland to compile my
> program.
>
> As a debugging step I have put in the
> long coresize = coreleft();
> printf("Core left in bytes %ld\n", coresize);
> lines of code every time I calloc and free memory. [...]
> [... and the results are mysterious.]


coreleft() is not part of the Standard C library, so
there's no telling what it might report or what the report
means. Consult your Borland documentation or a Borland
newsgroup. Also, see Question 7.25 in the comp.lang.c
Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      08-20-2003

"Britt Hibbert" <(E-Mail Removed)> wrote in message
>
> As a debugging step I have put in the
> long coresize = coreleft();
> printf("Core left in bytes %ld\n", coresize);
>

coreleft() isn't an ANSI function. The reason is that, on many systems, it
is not quite clear what constitutes "free" memory.
If you are using an old 16-bit DOS compiler on a new machine it wouldn't
surprise me if funny things are going on with the memory behind the scenes,
so "coreleft" doesn't do what you expect it to.



 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      08-20-2003
(E-Mail Removed) (Britt Hibbert) writes:

> ...the subsequent call to coreleft does not report this extra
> memory after it has been freed.


This is in the C FAQ:

7.25: I have a program which mallocs and later frees a lot of memory,
but I can see from the operating system that memory usage
doesn't actually go back down.

A: Most implementations of malloc/free do not return freed memory
to the operating system, but merely make it available for future
malloc() calls within the same program.
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MoVoIP - FREE MOBILE Inetrnet Phone Calls - FREE Internet Phone Calls ubifone VOIP 0 07-29-2005 04:31 PM



Advertisments