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?
Asked
Active
Viewed 395 times
3

Jo Liss
- 529
- 2
- 10
-
2This kind of question might be a better fit for [retrocomputing.se]? – amon Oct 15 '21 at 18:28
-
@amon I wasn't sure... Answers to [this meta question](https://meta.stackexchange.com/questions/97786/where-to-ask-questions-about-computer-science-history) suggest Software Engineering, Retrocomputing or Computer Science. – Jo Liss Oct 15 '21 at 21:55
1 Answers
8
I did some sleuthing in historic sources, and it seems that the "a" in "alloca" stands for "automatic", as in automatically freed.
The GNU man page says:
There is evidence that the alloca() function appeared in 32V,
PWB, PWB.2, 3BSD, and 4BSD. There is a man page for it in
4.3BSD. Linux uses the GNU version.
Linked from this commit message I found archives of UNIX/32V and PWB/UNIX sources, each of which contains an alloca.s
assembly file:
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>
I believe the alloc
function referenced would 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);
}

Jo Liss
- 529
- 2
- 10