home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!flop.ENGR.ORST.EDU!gaia.ucs.orst.edu!umn.edu!csus.edu!netcom.com!ersmith
- From: ersmith@netcom.com (Eric R. Smith)
- Newsgroups: comp.sys.atari.st.tech
- Subject: Re: Malloc (Was: Sending objc_draw to a buffer)
- Message-ID: <1993Jan13.030029.1407@netcom.com>
- Date: 13 Jan 93 03:00:29 GMT
- Article-I.D.: netcom.1993Jan13.030029.1407
- References: <wmtwen.726497985@rw8.urc.tue.nl> <1993Jan8.183133.12773@netcom.com> <1iv954INN1geq@rs1.rrz.Uni-Koeln.DE>
- Organization: Netcom Online Communications Services (408-241-9760 login: guest)
- Lines: 55
-
- In article <1iv954INN1geq@rs1.rrz.Uni-Koeln.DE> kim@vax.mpiz-koeln.mpg.dbp.de writes:
- >In <1993Jan8.183133.12773@netcom.com> ersmith@netcom.com (Eric R. Smith) writes:
- >
- >>The answer is quite simple: use malloc() and free(). This has 3 advantages:
- >
- >>(1) It will work in accessories, if your library is sensible (most are).
- >> The OS Malloc() function cannot be called from accessories at all.
- >
- >I have a question about this. From what I understand, malloc()
- >manages memory that is in turn allocated by Malloc() from the OS.
-
- This is generally true, but a clever library will detect whether the
- program is running as an accessory or an application and adjust malloc()
- to behave accordingly; for accessories, if the amount of memory requested
- would exhaust the initial 'pool' of memory that the accessory allocated
- when it was starting up, then the malloc() call will fail. For applications,
- the library malloc can of course call the OS Malloc to obtain more
- memory.
-
- (So whether malloc() is safe to use in an accessory depends on which
- library you're using. The GNU C and MiNT libraries certainly
- give the correct behaviour for accessories; I can't vouch for
- any others, but I'm sure some do.)
-
- >Two comments on this: Firstly, I have never understood why TOS
- >won't let accessories Malloc() their own memory, but considers
- >memory Malloc()'ed by accessories to belong to the main process
- >running at the time the Malloc() occurs. Does anyone know a
- >sensible reason why that is? Secondly, this silly problem may
- >become increasingly irrelevant when MultiTOS finally becomes
- >available...
-
- GEMDOS is a single tasking OS. That means that as far as GEMDOS is
- concerned, only one application is active at a time. GEM does some
- tricks to make it look to the user like accessories can also be
- active; but GEMDOS doesn't know about these tricks, all it knows about
- is its 1 main application. So every system call (including Malloc,
- and also including Fopen and other file calls) made to GEMDOS occurs
- in the context of the 1 GEMDOS program running, i.e. the "main"
- application.
-
- MultiTOS of course will change this. Actually, the whole concept of
- an "accessory" becomes rather irrelevant with MultiTOS (since there's
- no need for accessories, you can just write applications that stay
- around as long as the user wants). Of course MultiTOS does load
- accessories (for compatibility) and in fact every accessory becomes
- a separate MiNT process (so they can Malloc if they want to; but
- an accessory that takes advantage of this feature wouldn't work
- under old TOS, and as I said there's really no reason to write
- a MultiTOS-only accessory since they can't do anything normal
- applications can't do. Applications can even make a menu_register
- call to change the way their names appear in the "Desk" menu!)
-
- Regards,
- Eric
-