Talk:Memory allocation

From Rosetta Code

About langs like C, the task requires explanation about the fact that local variables are "allocated" on the stack (likely), so that a way of "allocating" 100 integers is simply int ints[100] ... even though this is not an explicit allocation? --ShinTakezou 16:51, 26 May 2009 (UTC)

Yes, please do explain the difference in lifetime and syntax of "auto" vs. malloc() allocations. --IanOsgood 16:53, 26 May 2009 (UTC)
POSIX should have also shmget and friends for shared memory (shared among processes, not threads)... but sincerely I've never used them :D --ShinTakezou 17:39, 26 May 2009 (UTC)

Task Applicability

I think this task does not apply to Tcl, and suspect it is not applicable to any other dynamic language either. They all leave memory management to their runtime; that's part of their charm. But I won't help them by marking tasks with {{Omit}} for them... —Dkf 19:11, 26 May 2009 (UTC)

I was hoping that even dynamic languages could show how to how to manage lifetimes of blocks of memory, for use in foreign function interfaces, for example. --IanOsgood 22:18, 26 May 2009 (UTC)

I am not clear on what exactly counts as allocating a "block" of memory. Does it mean you have to explicitly calculate the size of the memory you are allocating? or does allocating an object count? or allocating an array?

Because if you take the C example codes using malloc() and all, the equivalent way to do the things in C++ would be to use "new" and "new []", e.g. "new int" (allocates space for one int), "new int[10]" (allocates space for 10 ints), "new MyClass" (allocates space for one MyClass object, and initializes it at the same time). Notice that you don't have to manually calculate the sizes -- they are calculated for you from the type. So do these count for this task? Then you can take these a step further -- the last two of them can be translated into Java: "new int[10]" (allocates an array of 10 ints), "new MyClass()" (allocates space for one MyClass object, and initializes it at the same time). Do these Java allocations fall under this task too? --Spoon! 04:57, 27 May 2009 (UTC)