|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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.???? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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); } } |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
>> 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. |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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"... |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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??? |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|