PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > heap status
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
heap status

Réponse
 
LinkBack Outils de la discussion
Vieux 22/11/2007, 16h06   #1
aarklon@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut heap status

Hi all,

Is there a possible way to check the status of heap in ANSI-C
or standard C....????

if my memory is correct in the old turbo c++ 3.0 compiler there were
some macros by name _HEAPOK, _HEAPEMPTY, and
_HEAPCORRUPT , is there something similar to this in standard C.????
  Réponse avec citation
Vieux 22/11/2007, 16h24   #2
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

aarklon@gmail.com wrote:
> Hi all,
>
> Is there a possible way to check the status of heap in ANSI-C
> or standard C....????


Do you only read replies to your postings? We've recently pointed out
(once again) that C doesn't care about heaps, stacks or segments.

So the answer is simply - no. There may be a way with the implementation
you are using on a specific platform, but that is not part of the C
standard. You could ask on a newgroup which discusses the C
implementation and/or platform you are using.

By the way - as I understand it the standard is an ISO standard which
has been adopted by ANSI, so the "or" in your question is irrelevant.
  Réponse avec citation
Vieux 22/11/2007, 16h46   #3
James Kuyper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

aarklon@gmail.com wrote:
> Hi all,
>
> Is there a possible way to check the status of heap in ANSI-C
> or standard C....????
>
> if my memory is correct in the old turbo c++ 3.0 compiler there were
> some macros by name _HEAPOK, _HEAPEMPTY, and
> _HEAPCORRUPT , is there something similar to this in standard C.????


No.
  Réponse avec citation
Vieux 22/11/2007, 18h15   #4
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

aarklon@gmail.com wrote:

> Hi all,
>
> Is there a possible way to check the status of heap in ANSI-C
> or standard C....????


No.

What do you think "the status of the heap" means [I assume that
by "the heap" you mean the memory managed by malloc and friends],
and what would you do with the status if you had it?

--
Heaped Highly Hedgehog
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/

  Réponse avec citation
Vieux 22/11/2007, 18h23   #5
aarklon@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

On Nov 22, 1:15 pm, Chris Dollin <e...@electrichedgehog.net> wrote:
> aark...@gmail.com wrote:
> > Hi all,

>
> > Is there a possible way to check the status of heap in ANSI-C
> > or standard C....????

>
> No.
>
> What do you think "the status of the heap" means [I assume that
> by "the heap" you mean the memory managed by malloc and friends],
> and what would you do with the status if you had it?
>
> --
> Heaped Highly Hedgehog
> "We did not have time to find out everything we wanted to know."
> - James Blish, /A Clash of Cymbals/


I just saw a program in an old turbo c text as follows

#include<stdio.h>
#include<malloc.h>
#include<alloc.h>

main()
{
char *ch;
if(heapcheck() == _HEAPOK)
{
puts("Heap is correct");
ch = (char*) malloc(100);
gets(ch);
puts(ch);
free(ch);
getch();
}
else
{
puts("heap is corrupt");
puts("Press any key to exit");
exit(1);
}

}
  Réponse avec citation
Vieux 22/11/2007, 18h28   #6
James Kuyper
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

Chris Dollin wrote:
> aarklon@gmail.com wrote:
>
>> Hi all,
>>
>> Is there a possible way to check the status of heap in ANSI-C
>> or standard C....????

>
> No.
>
> What do you think "the status of the heap" means [I assume that
> by "the heap" you mean the memory managed by malloc and friends],
> and what would you do with the status if you had it?


Debug programs which have memory allocation problems. I've used
instrumented versions of the malloc() family for precisely this purpose,
with modest success.
  Réponse avec citation
Vieux 22/11/2007, 20h44   #7
Richard Tobin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

In article <65fae58c-2fd8-45d3-a88e-1f1ecf4d87de@d21g2000prf.googlegroups.com>,
<aarklon@gmail.com> wrote:

>I just saw a program in an old turbo c text as follows

[...]
> if(heapcheck() == _HEAPOK)
> {
> puts("Heap is correct");


Apart from the unportability, the use of such things is limited, since
if the heap has been corrupted it's quite possible that puts() won't
work, even if the program gets that far. What's more, it only detects
memory errors that corrupt the heap structures. For most situations,
I recommend testing your program extensively with an external checker
such as valgrind.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
  Réponse avec citation
Vieux 22/11/2007, 21h23   #8
jacob navia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

aarklon@gmail.com wrote:
> Hi all,
>
> Is there a possible way to check the status of heap in ANSI-C
> or standard C....????
>
> if my memory is correct in the old turbo c++ 3.0 compiler there were
> some macros by name _HEAPOK, _HEAPEMPTY, and
> _HEAPCORRUPT , is there something similar to this in standard C.????


Microsoft provides a lot of functions to debug the heap
Look into
http://msdn2.microsoft.com/en-us/lib...37(VS.71).aspx



--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
  Réponse avec citation
Vieux 23/11/2007, 07h49   #9
Chris Torek
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

>> aarklon@gmail.com wrote:
>>> Hi all,
>>>
>>> Is there a possible way to check the status of heap in ANSI-C
>>> or standard C....????


>Chris Dollin wrote:
>> No.
>>
>> What do you think "the status of the heap" means [I assume that
>> by "the heap" you mean the memory managed by malloc and friends],
>> and what would you do with the status if you had it?


In article <iTj1j.15980$Xg.6107@trnddc06>
James Kuyper <jameskuyper@verizon.net> wrote:
>Debug programs which have memory allocation problems. I've used
>instrumented versions of the malloc() family for precisely this purpose,
>with modest success.


Indeed. As I like to put it, using an invalid pointer value, such
as:

#include <stdlib.h>
#include <string.h>

char *buggy_dupstr(const char *str) {
return strcpy(malloc(strlen(str)), str); /* two bugs in one! */
}

can "plant a time bomb" in the runtime system. Having some way
to "make the bomb go off sooner" can be ful in locating the
code that planted it.

Or, of course, one can use a system that has "fat pointers", where
the error is trapped even sooner. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
  Réponse avec citation
Vieux 23/11/2007, 08h01   #10
karthikbalaguru
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

On Nov 22, 9:06 pm, aark...@gmail.com wrote:
> Hi all,
>
> Is there a possible way to check the status of heap in ANSI-C
> or standard C....????
>
> if my memory is correct in the old turbo c++ 3.0 compiler there were
> some macros by name _HEAPOK, _HEAPEMPTY, and
> _HEAPCORRUPT , is there something similar to this in standard C.????


It is available with Microsoft Visual C++ and not with C.

Karthik Balaguru
  Réponse avec citation
Vieux 23/11/2007, 08h46   #11
Chris Dollin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

James Kuyper wrote:

> Chris Dollin wrote:
>> aarklon@gmail.com wrote:
>>
>>> Hi all,
>>>
>>> Is there a possible way to check the status of heap in ANSI-C
>>> or standard C....????

>>
>> No.
>>
>> What do you think "the status of the heap" means [I assume that
>> by "the heap" you mean the memory managed by malloc and friends],
>> and what would you do with the status if you had it?

>
> Debug programs which have memory allocation problems. I've used
> instrumented versions of the malloc() family for precisely this purpose,
> with modest success.


That's what /you/ would do, James [and it's a good answer], but I wondered
what the OP was going to do -- sometimes context s shape a decent
answer. (And sometimes it leaves one -- this one, anyway -- floundering;
nothing is perfect ...)

--
Chris "perfectly imperfect. Or imperfectly perfect?" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

  Réponse avec citation
Vieux 23/11/2007, 08h52   #12
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

jacob navia wrote:
> aarklon@gmail.com wrote:
>> Hi all,
>>
>> Is there a possible way to check the status of heap in ANSI-C
>> or standard C....????
>>
>> if my memory is correct in the old turbo c++ 3.0 compiler there were
>> some macros by name _HEAPOK, _HEAPEMPTY, and
>> _HEAPCORRUPT , is there something similar to this in standard C.????

>
> Microsoft provides a lot of functions to debug the heap
> Look into
> http://msdn2.microsoft.com/en-us/lib...37(VS.71).aspx


The OP asked about "ANSI-C or standard C"...
  Réponse avec citation
Vieux 23/11/2007, 13h13   #13
aarklon@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

On Nov 23, 2:49 am, Chris Torek <nos...@torek.net> wrote:
> >> aark...@gmail.com wrote:
> >>> Hi all,

>
> >>> Is there a possible way to check the status of heap in ANSI-C
> >>> or standard C....????

> >Chris Dollin wrote:
> >> No.

>
> >> What do you think "the status of the heap" means [I assume that
> >> by "the heap" you mean the memory managed by malloc and friends],
> >> and what would you do with the status if you had it?

>
> In article <iTj1j.15980$Xg.6107@trnddc06>
> James Kuyper <jameskuy...@verizon.net> wrote:
>
> >Debug programs which have memory allocation problems. I've used
> >instrumented versions of the malloc() family for precisely this purpose,
> >with modest success.

>
> Indeed. As I like to put it, using an invalid pointer value, such
> as:
>
> #include <stdlib.h>
> #include <string.h>
>
> char *buggy_dupstr(const char *str) {
> return strcpy(malloc(strlen(str)), str); /* two bugs in one! */
> }
>
> can "plant a time bomb" in the runtime system. Having some way
> to "make the bomb go off sooner" can be ful in locating the
> code that planted it.
>
> Or, of course, one can use a system that has "fat pointers", where
> the error is trapped even sooner. :-)


can you give a simple example for fat pointer in standard C..???
as my understanding goes they are pointers that does range checking
isn't it???

  Réponse avec citation
Vieux 23/11/2007, 14h08   #14
Mark Bluemel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: heap status

aarklon@gmail.com wrote:

> can you give a simple example for fat pointer in standard C..???
> as my understanding goes they are pointers that does range checking
> isn't it???


There's a good discussion in Chris Torek's post here -
http://groups.google.co.uk/group/com...0afd4140ae1632
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h37.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24359 seconds with 22 queries