🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #13245

Re: Memory allocation

#13245
From: Chris Wichura
Date: Sun, 31 Dec 1989 01:03
29 lines
2044 bytes
Every time a routine is called it will use the stack.  The return address
gets pushed on and then most coimpilers will use a LINK command to get
a local frame to store variables in.  Thus, your copyfile() routine will
eat up well over 1024 bytes from the stack when it is called as you have
the buffer set at that size.  On the amiga the stack is usually used as
the heap as well.
 
So there are two things you can do to help your program be less of a
stack-o-hollic:
 
1)  Instead of using the char buf[1024] use a char *buf and call your
    favorite memory alloc routine (ArpAlloc(), AllocMem(), malloc(), etc)
    to get the storage for the buffer and then free the memory after the
    copy file routine is done.  This will drastically reduce the amount
    of stack space your copyfile routine needs.
 
2)  If you can get around using a recursive function then by all means so
    so.  I had a routine that scanned a dir and did various things that
    needed a stack of 30k to work with my HD (I have some rather sever
    levels of directory depth in some places...).  I re-wrote the routine
    inside a big for(;;) {} loop adding a couple of variables to make it
    `think' it was recursive and now the same program will work just dandy
    with a 4000 byte stack (the AmigaDOS default).
 
Idea two usually tends to be a fair amount trickier than the first one :-)
-- 
Christopher A. Wichura
u12401 @ uicvm.uic.edu  (my home account)
caw @ jolnet.UUCP       (my Usenet feed)
Technical Details
Message-ID: <2617@jolnet.ORPK.IL.US>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!uakari.primate.wisc.edu!ames!attctc!jolnet!caw
References: <Dec.30.13.09.02.1989.28450@topaz.rutgers.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!uakari.primate.wisc.edu!ames!attctc!jolnet!caw
From: caw@jolnet.ORPK.IL.US (Chris Wichura)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Memory allocation
Keywords: stack size, heap, Lattice 5.04
Message-ID: <2617@jolnet.ORPK.IL.US>
Date: 31 Dec 89 01:03:55 GMT
References: <Dec.30.13.09.02.1989.28450@topaz.rutgers.edu>
Reply-To: caw@jolnet.UUCP (Chris Wichura)
Organization: Jolnet, Public Access Unix, Orland Park (Joliet), Ill.
Lines: 29