| | |
Another question regarding memory
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hello,
You're welcome. If you have any further questions regarding the information I provided, don't hesitate to ask.
- Stack Overflow
You're welcome. If you have any further questions regarding the information I provided, don't hesitate to ask.
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
•
•
Join Date: Jan 2005
Posts: 33
Reputation:
Solved Threads: 0
Dear Stack Overflow,
I have a funny observation which I am not sure if it makes any sense. With regards to your code
it appears that when I use it to free up memory used for my graph G in the main program, it works, but when I write it as a function and include it as a header file as follows
it doesn't work. I passed my graph G to this function and then had the following code in my main function
I got fail instead of the expected success. Why is this so?
I have a funny observation which I am not sure if it makes any sense. With regards to your code
C Syntax (Toggle Plain Text)
/* free rows made by MATRIXint() */ /* where V represents the rows */ for (i = V-1; i >= 0; i--) { if (G->adj[i] != NULL) { free(G->adj[i]); G->adj[i] = NULL; } } /* free 2-dimensional pointer */ if (G->adj != NULL) { free(G->adj) G->adj = NULL; } /* free Graph */ if (G != NULL) { free(G); G = NULL; }
it appears that when I use it to free up memory used for my graph G in the main program, it works, but when I write it as a function and include it as a header file as follows
C Syntax (Toggle Plain Text)
void freegraph(G) { int i; /* free rows made by MATRIXint() */ /* where V represents the rows */ for (i = (G->V)-1; i >= 0; i--) { if (G->adj[i] != NULL) { free(G->adj[i]); G->adj[i] = NULL; } } /* free 2-dimensional pointer */ if (G->adj != NULL) { free(G->adj) G->adj = NULL; } /* free Graph */ if (G != NULL) { free(G); G = NULL; }
C Syntax (Toggle Plain Text)
if(G==NULL)printf("success"); else printf("fail");
![]() |
Similar Threads
- Question about memory/RAM (Motherboards, CPUs and RAM)
- Two quick question about memory... (C++)
- How to free up memory used for queues? (C)
- is there a program where there is only 32k in the main memory. (C++)
Other Threads in the C Forum
- Previous Thread: strange problem
- Next Thread: problem
Views: 4277 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest homework i/o ide infiniteloop initialization interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32 win32api windows.h





