Inherits @74::ref_counted.
Public Member Functions | |
| void * | malloc (std::size_t bytes) |
| Allocate an object in the apartment. | |
| void | free (void *p) |
| Free an object in the apartment. | |
| void | defrag () |
| Defragment the heap (if supported by the memory manager). | |
| gc::garbage_collector & | gc () const |
| Access the apartment's garbage collector. | |
| void | enter () |
| Enter the apartment. | |
| void | lock () |
| Locks the apartment. | |
| void | unlock () |
| Unlocks the apartment. | |
Static Public Member Functions | |
| static apartment * | current () |
| Gets a pointer to the current apartment. | |
All objects in C++Script are managed by an apartment. Roughly speaking, there is one apartment per thread, and the programmer can create further apartments as necessary.
Apartments are "acquired" and "released", and an thread must enter an apartment prior to accessing any data in the apartment.
This scheme is efficient because all objects are threadsafe, and there is no overhead when using objects or allocating memory. The only time there is overhead is when threads change apartments for some reason, for example to access an object in a different apartment. Cross-apartment access must be strictly regulated using a dynamic::types::proxy_impl object.
The apartment runs the garbage collector independently, which does not block the operation of other threads.
I realise this memory model is a bit wierd but it is completely scalable to any number of threads without overhead.
Definition at line 104 of file proxy.cpp.
| static apartment* dynamic::apartment::current | ( | ) | [inline, static] |
Gets a pointer to the current apartment.
Note that there will be a different apartment per thread.
Definition at line 141 of file proxy.cpp.
Referenced by dynamic::internal::apartment_defrag(), dynamic::internal::apartment_free(), dynamic::internal::apartment_malloc(), enter(), and dynamic::gc::global_gc().
| void dynamic::apartment::enter | ( | ) | [inline] |
| void dynamic::apartment::lock | ( | ) | [inline] |
1.5.7.1