Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!purdue!decwrl!labrea!polya!rokicki From: rokicki@polya.Stanford.EDU (Tomas G. Rokicki) Newsgroups: comp.sys.amiga.tech Subject: Chip RAM Message-ID: <3150@polya.Stanford.EDU> Date: 29 Jun 88 17:02:33 GMT Organization: Stanford University Lines: 51 This is more like it, folks, for checking whether a data structure is in Chip RAM or not. Sorry for giving you such bad code, Glenn, but it was off the top of my head, on a machine without a compiler. So, anyway, folks, stop linking with that option that puts the entire data segment in Chip RAM; waste a byte or two and do something like this. #include "stdio.h" #include "functions.h" #include "exec/memory.h" #include "intuition/intuition.h" long TypeOfMem() ; /* why isn't this in functions.h? */ struct Image foo ; struct Image *usefoo ; void cleanup() { /* how to clean up after */ if (usefoo != &foo) FreeMem(usefoo, (long)sizeof(struct Image)) ; } void error(s) /* how to die */ char *s ; { printf("%s!\n", s) ; cleanup() ; } void *checkchip(data, len) /* this is the important function */ 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) ; } void initialize() { /* how to use, might also check for 1.2 */ usefoo = (struct Image *)checkchip(&foo, sizeof(struct Image)) ; } void main() { initialize() ; cleanup() ; } -- /-- Tomas Rokicki /// Box 2081 Stanford, CA 94309 / o Radical Eye Software /// (TAMU EE '85) (415) 326-5312 \ / | . . . or I \\\///Join CCFFAALW---Concerned Citzens V | won't get dressed \XX/Fighting For An Acronym-Less World