MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / allocate

Method allocate

include/daScript/misc/memory_model.h:82–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 return ((b & (1u<<j))!=0);
81 }
82 __forceinline char * allocate ( ) {
83 if ( allocated == total ) return nullptr;
84 uint64_t maxt = total / 32;
85 for ( uint64_t t=0; t!=maxt; ++t ) {
86 uint32_t b = bits[look];
87 uint32_t nb = ~b;
88 if ( nb ) {
89 uint32_t j = 31 - das_clz(nb);
90 bits[look] = b | (1u<<j);
91 allocated ++;
92 uint64_t ofs = (look * 32 + j);
93 DAS_ASSERT(ofs < total);
94 return data + ofs * size;
95 }
96 look = look + 1;
97 if ( look == maxt ) look = 0;
98 }
99 DAS_ASSERT(0 && "allocated reports room, but no bits are available");
100 return nullptr;
101 }
102 __forceinline void free ( char * ptr ) {
103 ptrdiff_t idx = (ptr - data) / size;
104 DAS_ASSERT ( idx>=0 && idx<ptrdiff_t(total) );

Callers 12

computeMethod · 0.45
computeMethod · 0.45
computeMethod · 0.45
computeMethod · 0.45
computeMethod · 0.45
impl_allocateFunction · 0.45
reserveInternalMethod · 0.45
makeMethod · 0.45
make_and_initMethod · 0.45
makeMethod · 0.45
makeMethod · 0.45
allocateMethod · 0.45

Calls 1

das_clzFunction · 0.85

Tested by

no test coverage detected