Sunday, June 18, 2006
Static vs. Dynamic Memory Allocation & Stack vs. Heap
http://www.cs.jcu.edu.au/Subjects/cp2003/1997/foils/heapAndStack/heapAndStack.html
> example
>
>int x; /* static storage */
>
>void main() {
> int y; /* dynamic stack storage */
> char *str; /* dynamic stack storage */
>
> str = malloc(100); /* allocates 100 bytes of dynamic heap storage */
>
> y = foo(23);
> free(str); /* deallocates 100 bytes of dynamic heap storage */
>} /* y and str deallocated as stack frame is popped */
>
>int foo(int z) { /* z is dynamic stack storage */
> char ch[100]; /* ch is dynamic stack storage */
>
> if (z == 23) foo(7);
>
> return 3; /* z and ch are deallocated as stack frame is popped,
> 3 put on top of stack */
>}
>
Static vs. Dynamic Memory Allocation & Stack vs. Heap
int x; /* static storage */ void main() { int y; /* dynamic stack storage */ char *str; /* dynamic stack storage */ str = malloc(100); /* allocates 100 bytes of dynamic heap storage */ y = foo(23); free(str); /* deallocates 100 bytes of dynamic heap storage */ } /* y and str deallocated as stack frame is popped */ int foo(int z) { /* z is dynamic stack storage */ char ch[100]; /* ch is dynamic stack storage */ if (z == 23) foo(7); return 3; /* z and ch are deallocated as stack frame is popped, 3 put on top of stack */ }
Tuesday, June 06, 2006
ThStroustrup: FAQ: "Java isn't platform independent; it is a platform. Like Windows, it is a proprietary commercial platform. That is, you can write programs for Windows/Intel or Java/JVM, and in each case you are writing code for a platform owned by a single corporation and tweaked for the commercial benefit of that corporation. It has been pointed out that you can write programs in any language for the JVM and associated operating systems facilities. However, the JVM, etc., are heavily biased in favor of Java. It is nowhere near being a general reasonably language-neutral VM/OS."