From: nick s. <nic...@gm...> - 2006-10-07 10:55:05
|
Dear Blitz developers I've been looking at memory usage of blitz arrays, and can see that memory blocks contain a mutex (24 bytes on GNU x86), which could be replaced with atomic operations such as (GNU x86): #ifdef BZ_THREADSAFE_ATOMIC_OPS #ifdef BZ_DEBUG_REFERENCE_ROLLOVER void incrementReferences() { __asm__ __volatile__("lock incb %0" : "+m" (references_)); } void decrementReferences() { __asm__ __volatile__("lock decb %0" : "+m" (references_)); } #else void incrementReferences() { __asm__ __volatile__("lock incl %0" : "+m" (references_)); } void decrementReferences() { __asm__ __volatile__("lock decl %0" : "+m" (references_)); } #endif int readReferences() { return references_; } #else void incrementReferences() { ++references_; } void decrementReferences() { --references_; } int readReferences() { return references_; } #endif Statements such as ++references_; and --references_; and int refcount = references_; thus become incrementReferences(); and incrementReferences(); and int refcount = readReferences() The atomic operations could be abstracted for multi-platform implementation. The original mutex code would remain and would be overwridden by defining BZ_THREADSAFE_ATOMIC_OPS. A single line changes in blitz.h: #if defined BZ_THREADSAFE && ! defined BZ_THREADSAFE_USE_ATOMIC_OPS Removing this extra 24 bytes per memory block is of great interest when creating large numbers of small, non-shared arrays. I would thus like to propose this modification. Any comments? Regards Nicholas |