D - Non-"new" Entry to GC?
- Russell Lewis (21/21) Aug 22 2002 Somebody mentioned smart pointers and how they might be separate from
- Sean L. Palmer (9/30) Aug 23 2002 I definitely like this.
- Walter (1/1) Aug 24 2002 It's a good idea. -Walter
Somebody mentioned smart pointers and how they might be separate from normal GC issues. It got me thinking: it would be nice to be able to take a block of memory and hand it off to the GC, along with a routine that should be used to release it. In particular, I was thinking about mmap() calls. For those who don't already know, mmap() takes a file pointer and has the kernel set up a region in memory where the contents of that file are mapped to. You can then read the contents just like an array, instead of using the fgets() function or something like that. What if you could to this: char[] gc_mmap(FILE *fp) { void *ptr = mmap(...); gc.AddRegion(ptr, <length>, &munmap); return (char[<len>])ptr; } Then, the user would call gc_mmap instead of the standard mmap defined by the OS. He would get a char[] from it, which he could use to read the data. At some point in the future, when the last reference to that location was lost, the GC would recognize that the data was now garbage. However, instead of its normal cleanup routines, it would call the callback function you gave it (munmap, in this case) to release the memory.
Aug 22 2002
I definitely like this. Heck for handles you could specify a 1-byte "memory" region at the handle's value and a special cleanup function to release the handle. But for handles allocated sequentially from 1 this wouldn't work so well if there were multiple kinds of handles. Sean "Russell Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3D655542.9050807 deming-os.org...Somebody mentioned smart pointers and how they might be separate from normal GC issues. It got me thinking: it would be nice to be able to take a block of memory and hand it off to the GC, along with a routine that should be used to release it. In particular, I was thinking about mmap() calls. For those who don't already know, mmap() takes a file pointer and has the kernel set up a region in memory where the contents of that file are mapped to. You can then read the contents just like an array, instead of using the fgets() function or something like that. What if you could to this: char[] gc_mmap(FILE *fp) { void *ptr = mmap(...); gc.AddRegion(ptr, <length>, &munmap); return (char[<len>])ptr; } Then, the user would call gc_mmap instead of the standard mmap defined by the OS. He would get a char[] from it, which he could use to read the data. At some point in the future, when the last reference to that location was lost, the GC would recognize that the data was now garbage. However, instead of its normal cleanup routines, it would call the callback function you gave it (munmap, in this case) to release thememory.
Aug 23 2002