DBM-Deep-Blue
view release on metacpan or search on metacpan
------------------------------------------------------------------------
Copy memory area from a to b
------------------------------------------------------------------------
*/
void allocCopy(M **m, UL a, UL b, UL l)
{
UL L = 1<<l; // Length of object to copy
UL V = (*m)->centralVector; // Central Vector
UL S = (*m)->spona; // Spona
UL nV = V; // In case Central Vector is relocated
UL nS = S; // In case Spona is relocated
// Relocate allocated areas contained in this block
if (V != MMU)
{UL p = a;
for(; p < a+L;)
{UL fb = findFree(*m, p, l); // Is this a free area
if (fb > 0)
{setFreeAddress2(*m, p + b - a, fb); // Update position of free area
p += 1<<fb; // Skip over free area
continue;
}
// Block size of allocated area
UL B = getAllocLength(*m, p);
// Skip Central Vector as it is immediately relocatable
if (p == V)
{nV = p + b - a; // New position for CV
p += 1<<B; // Skip CV
continue;
}
// Skip Spona as it is immediately relocatable
if (p == S)
{nS = p + b - a; // New position for spona
p += 1<<B; // Skip spona
continue;
}
// Allocated block - relocate any contained object
if (B >= MemoryMinimumSize)
{UL o = getObjectNumber(*m, p); // Get object number
// Objects with object number of zero or > MMU/2 do not not need relocation
if (o > 0 && o < MMU/2)
{UL Q = getObject(m, o); // Check CV integrity
if (p == Q) // Check CV integrity
{setObjectPointer(m, o, p + b - a); // Update CV
}
else // CV integrity has failed
{croak("Non object o=%u a=%u b=%u B=%u p=%u Q=%u", o, a, b, B, p, Q);
}
(*m)->centralVector = v; // Save offset of CV
setCVX(*m, l); // Save extent of CV
clearCV(*m); // Clear CV
}
return v;
}
/*
------------------------------------------------------------------------
Re-allocate and relocate Central Vector
------------------------------------------------------------------------
*/
void reallocCV(M **m)
{
UL V = allocCV(m); // Address of CV
UL l = getAllocLength(*m, V); // Size of block
UL s = getCVX(*m); // Size needed for CV
if (s == 0) // CV no longer needed
void reallocObject(M **m, UL o, UL s, void (*copy)(M **m, UL from, UL to, UL l))
{
UL l = bits(s + sizeof(struct O)); // Log2(Size of required block)
UL p = allocMemory(m, l); // Allocate a memory block that is big enough
UL q = getObject (m, o); // Offset of existing object
// Set object number of new allocation
putObjectInCV ( m, o, p); // Update CV, its an existing object so CVT will not change
setObjectNumber(*m, q, 0); // Zero object number of old object so that allocCopy will not relocate it
// Copy data if copy function supplied
if (copy)
{(*copy)(m, q, p, l);
}
// Copy referenceCount and type from old to new object
{O *P = am(*m, p);
( run in 0.950 second using v1.01-cache-2.11-cpan-71847e10f99 )