The alloca() function allocates memory in the stack frame of the caller. What did alloca originally stand for? Are there any sources regarding the etymology of the name?
1 Answers
I did some sleuthing in historic sources, and it seems that the "a" suffix in "alloca" stands for "automatic". "Automatic" is probably used in the sense of "automatically freed" or "automatic variable" (as in auto, the default C storage class for local variables; see discussion in the comments).
This commit message by Alejandro Colomar suggests that alloca appeared (separately?) in UNIX/32V and PWB/UNIX (both from the late 1970s). In the source archives linked, I found that each of those contains an alloca.s assembly file, each of which in turn refers to alloca as "automatic":
32v/usr/src/libc/sys/alloca.s
# like alloc, but automatic
# automatic free in return
.globl _alloca
_alloca:
.word 0x0000
subl2 4(ap),sp # crude allocation
movl 16(fp),r1 # pc
movq 8(fp),ap # new (old) ap and fp
bicl2 $3,sp # 4-byte align
addl2 $7*4,sp # reuse space of mscp
movl sp,r0 # return value
jmp (r1) # funny return
spencer_pwb/sys/source/s4/util/alloca.s
/ wdptr = alloca(nbytes);
/ like alloc, but automatic
/ automatic free upon return from calling function
.globl _alloca
_alloca:
mov (sp)+,r1 / return
mov (sp),r0 /count
inc r0
bic $1,r0 / round up
sub r0,sp / take core
mov sp,r0
tst (r0)+ / returned value; will generate
/ a memory fault if there isn't enough core
jmp (r1)
.data
<@(#)alloca 1.1\0>
P.S. When they say "like alloc", the alloc function they're referring to seems be a predecessor of the modern malloc, based on this function definition in PWB:
spencer_pwb/sys/source/s4/alloc.c
/* alloc - old-style memory allocator
* returns -1 on fail rather than 0
*/
alloc(n)
{
register p;
p = malloc(n);
return(p?p:-1);
}
- 599