Article View: comp.sys.amiga.tech
Article #9212Tip for effective memory usage
From: Glenn M. Lewis
Date: Wed, 29 Jun 1988 04:47
Date: Wed, 29 Jun 1988 04:47
45 lines
1602 bytes
1602 bytes
[]
This little gem was sent to me by Tomas Rokicki (of AmigaTeX, previewer,
profiler, BlitLab, etc., fame). It checks to see if data that *needs* to be
in MEMF_CHIP is *already* in MEMF_CHIP, and if so, does not AllocMem() more
chip memory wastefully, but leaves it there and returns a pointer to it.
I thought this was worth passing on. I haven't tested it yet, but it
sure looks good :-)
-- Glenn Lewis
>From: Tomas G. Rokicki <rokicki@polya.Stanford.EDU>
[Here] is a function that tells you if something is in Chip RAM or not:
TypeOfMem(ptr)
will return memory type; AND it with MEMF_CHIP to see if things are
already in Chip. Thus, you might do something like
struct Image foo = { . . . }
struct Image *usefoo ;
initialize() {
foo = (struct Image *)checkchip(foo, sizeof(struct Image)) ;
}
void *checkchip(data, len)
void *data ;
int len ;
{
void *ptr ;
if (TypeOfMem(data) & MEMF_CHIP)
return(data) ;
ptr = AllocMem((long)len, MEMF_CHIP) ;
if (ptr == NULL)
error("! out of core") ;
CopyMem(data, ptr, (long)len) ;
return(ptr) ;
}
--
glewis@cit-vax.caltech.edu
Technical Details
Message-ID:
<7109@cit-vax.Caltech.Edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!oberon!cit-vax!glewisShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!oberon!cit-vax!glewis From: glewis@cit-vax.Caltech.Edu (Glenn M. Lewis) Newsgroups: comp.sys.amiga.tech Subject: Tip for effective memory usage Message-ID: <7109@cit-vax.Caltech.Edu> Date: 29 Jun 88 04:47:19 GMT Reply-To: glewis@cit-vax.UUCP (Glenn M. Lewis) Distribution: na Organization: California Institute of Technology Lines: 45