| | |
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
| Thread Tools | Search this Thread |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings structures systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi





