News for hackers. Stuff that matters.
Re:Rust: Dropping heavy things in another thread can make yo... by projektfu on Saturday May 30, 2020 @03:15PM (#23363802)
Yeah, I like Apple’s (Next’s) approach of pool allocation for each run through the event loop. Defer dealloc, drop pool at the end.
Re:Rust: Dropping heavy things in another thread can make yo... by saurik on Saturday May 30, 2020 @03:29PM (#23363887)
Apple's pools are for helping manage reference counts of returned objects (via autorelease) but aren't doing pool allocation (as any of those objects could escape, so you can't do the fast thing of just deallocating the pool). The normal memory allocator is used while in the scope of an autorelease pool.
Re:Rust: Dropping heavy things in another thread can make yo... by projektfu on Saturday May 30, 2020 @06:21PM (#23365309)
True, I was thinking the same after I posted. Maybe I’m thinking more of Apache’s approach and how it gets some of the benefits of a fork-per-request server without the overhead.
Re:Rust: Dropping heavy things in another thread can make yo... by andrekandre on Saturday May 30, 2020 @09:27PM (#23366420)
right, so if you do

@autoreleasePool { [[[SomeObject alloc] init] autorelease]; }//someobject is release after exiting this scope

//inside main runloop, not inside @autorelease{} [[[AnotherObject alloc] init] autorelease];

//AnotherObject will be release at end of main runloop

[[NotAutoreleased alloc] init]; //will leak past runloop iteration

is that understanding correct?

Re:Rust: Dropping heavy things in another thread can make yo... by mcguire on Saturday May 30, 2020 @03:33PM (#23363912)
Unless your destructors do more than deallocation, in which case you will leak whatever other resource you're managing.
Re:Rust: Dropping heavy things in another thread can make yo... by MaxBarraclough on Saturday May 30, 2020 @04:19PM (#23364302)
A pool can invoke destructors when it is cleared. Might take a bit of overhead (if the pool is to support arbitrary classes), but you could retain the fast pointer-bump allocation.
Re:Rust: Dropping heavy things in another thread can make yo... by ShroudedNight on Saturday May 30, 2020 @07:59PM (#23365959)
Not Rust, C++, but in case anybody wants an example: https://github.com/eclipse/omr/commit/fd99ca42fdbed76cc00e68...

TR::Region is the slab allocator used by the JIT in OpenJ9/OMR. The linked commit adds functionality for calling destructors of arbitrary types allocated in the Region.

Re:Rust: Dropping heavy things in another thread can make yo... by MaxBarraclough on Sunday May 31, 2020 @02:18PM (#23371420)
Interesting, thanks. Seems to require use of a common base class though, i.e. to use a class with this pool, you have to inherit from Destructable, or else create a subclass that does. Seems ugly. Perhaps that's the only way it can be done in C++ though.
Re:Rust: Dropping heavy things in another thread can make yo... by projektfu on Monday June 01, 2020 @03:45PM (#23382873)
It does create an object with that base class for the allocator but returns an object of the type you want from the allocator, using a template (Region::Instance<T>). So the API user only sees the types it's interested in.