Exemple #1
0
	bool ByteArray::Grow(uint32_t minimumCapacity)
	{
		if (minimumCapacity > m_capacity)
		{
			uint32_t newCapacity = m_capacity << 1;			
			if (newCapacity < minimumCapacity)
			{
				newCapacity = minimumCapacity;
			}
			if (newCapacity < kGrowthIncr) 
			{
				newCapacity = kGrowthIncr;
			}
			U8 *newArray = mmfx_new_array(uint8_t, newCapacity);
			if (!newArray)
			{
				return false;
			}
			if (m_array)
			{
				VMPI_memcpy(newArray, m_array, m_length);
				mmfx_delete_array(m_array);
			}
			VMPI_memset(newArray+m_length, 0, newCapacity-m_capacity);
			m_array = newArray;
			m_capacity = newCapacity;
			NotifySubscribers();
		}
		return true;
	}
Exemple #2
0
 // The cache structure is expected to be small in the normal case, so use a
 // linear list.  For some programs, notably classical JS programs, it may however
 // be larger, and we may need a more sophisticated structure.
 uint32_t LookupCacheBuilder::allocateCacheSlot(uint32_t imm30)
 {
     for ( int i=0 ; i < next_cache ; i++ )
         if (caches[i] == imm30)
             return i;
     if (next_cache == num_caches) {
         uint32_t newcap = num_caches + num_caches/2 + 5; // 0 5 12 23 39 66 ...
         uint32_t* new_cache = mmfx_new_array(uint32_t, newcap);
         if (num_caches > 0) {
             VMPI_memcpy(new_cache, caches, sizeof(uint32_t)*num_caches);
             mmfx_delete_array(caches);
         }
         caches = new_cache;
         num_caches = newcap;
     }
     caches[next_cache] = imm30;
     return next_cache++;
 }
Exemple #3
0
	ByteArray::ByteArray(const ByteArray &lhs) 
        // GCC will warn if we don't explicitly init GlobalMemoryProvider, 
        // even though it has no fields or ctor... sigh
        : GlobalMemoryProvider()
	{
		m_subscriberRoot = NULL;
		m_array    = mmfx_new_array(uint8_t, lhs.m_length);
		if (!m_array)
		{
			ThrowMemoryError();
			return;
		}

		m_capacity = lhs.m_length;
		m_length   = lhs.m_length;

		VMPI_memcpy(m_array, lhs.m_array, m_length);
	}