Path: 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 [] 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[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