XalanAllocationGuard(
             MemoryManager&  theMemoryManager,
             size_type       theSize) :
     m_memoryManager(theMemoryManager),
     m_pointer(theMemoryManager.allocate(theSize))
 {
 }
Example #2
0
SerializedBuffer SerializedBuffer::allocate_value_only_buffer(
	MemoryManager &memory_manager,
	size_type maximum_record_count,
	size_type total_record_size,
	identifier_type target_node)
{
	size_type buffer_size = 0;
	// Common header
	const ptrdiff_t common_header_ptrdiff = buffer_size;
	buffer_size += sizeof(SerializedBufferHeader);
	// Values
	const ptrdiff_t values_header_ptrdiff = buffer_size;
	buffer_size += sizeof(SerializedValuesHeader);
	buffer_size  = align_ceil(buffer_size, alignof(max_align_t));
	const ptrdiff_t values_data_ptrdiff = buffer_size;
	buffer_size += align_ceil(total_record_size, alignof(size_type)); // data
	const ptrdiff_t values_offsets_ptrdiff = buffer_size;
	buffer_size += (maximum_record_count + 1) * sizeof(size_type);    // offsets

	LockedMemoryReference locked_reference;
	if(target_node == TARGET_NODE_UNSPECIFIED){
		locked_reference = memory_manager.allocate(buffer_size).lock();
	}else{
		locked_reference =
			memory_manager.allocate(buffer_size, target_node).lock();
	}
	const auto ptr =
		reinterpret_cast<uintptr_t>(locked_reference.pointer());

	const auto common_header =
		reinterpret_cast<SerializedBufferHeader *>(
			ptr + common_header_ptrdiff);
	common_header->key_buffer_size = 0;
	common_header->value_buffer_size =
		static_cast<size_type>(buffer_size - values_header_ptrdiff);

	const auto values_header =
		reinterpret_cast<SerializedValuesHeader *>(
			ptr + values_header_ptrdiff);
	values_header->data_buffer_size =
		static_cast<size_type>(
			values_offsets_ptrdiff - values_data_ptrdiff);
	values_header->maximum_record_count = maximum_record_count;
	values_header->actual_record_count = 0;

	return SerializedBuffer(locked_reference);
}
Example #3
0
/***
 * 2.5.1.2 List datatypes   
 *   
 * The canonical-lexical-representation for the ·list· datatype is defined as 
 * the lexical form in which each item in the ·list· has the canonical 
 * lexical representation of its ·itemType·.
 ***/
const XMLCh* ListDatatypeValidator::getCanonicalRepresentation(const XMLCh*         const rawData
                                                             ,       MemoryManager* const memMgr
                                                             ,       bool                 toValidate) const
{
    MemoryManager* toUse = memMgr? memMgr : getMemoryManager();
    ListDatatypeValidator* temp = (ListDatatypeValidator*) this;
    temp->setContent(rawData);
    BaseRefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(rawData, toUse);
    Janitor<BaseRefVectorOf<XMLCh> > janName(tokenVector);    

    if (toValidate)
    {
        try
        {
            temp->checkContent(tokenVector, rawData, 0, false, toUse);
        }
        catch (...)
        {
            return 0;
        }
    }
   
    unsigned int  retBufSize = 2 * XMLString::stringLen(rawData);
    XMLCh* retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh));
    retBuf[0] = 0;
    XMLCh* retBufPtr = retBuf;
    DatatypeValidator* itemDv = this->getItemTypeDTV();

    try 
    {
        for (unsigned int i = 0; i < tokenVector->size(); i++)
        {
            XMLCh* itemCanRep = (XMLCh*) itemDv->getCanonicalRepresentation(tokenVector->elementAt(i), toUse, false);
            unsigned int itemLen = XMLString::stringLen(itemCanRep); 

            if(retBufPtr+itemLen+2 >= retBuf+retBufSize)
            {
                // need to resize
                XMLCh * oldBuf = retBuf;
                retBuf = (XMLCh*) toUse->allocate(retBufSize * sizeof(XMLCh) * 4);
                memcpy(retBuf, oldBuf, retBufSize * sizeof(XMLCh ));
                retBufPtr = (retBufPtr - oldBuf) + retBuf;
                toUse->deallocate(oldBuf);
                retBufSize <<= 2;
            }

            XMLString::catString(retBufPtr, itemCanRep);
            retBufPtr = retBufPtr + itemLen + 1;
            *(retBufPtr++) = chSpace;
            *(retBufPtr) = chNull;
            toUse->deallocate(itemCanRep);
        }

        return retBuf;

    }
    catch (...)
    {
        return 0;
    }
}
Example #4
0
		T *createOperation() {
			auto memory = memoryManager->allocate(sizeof(T), alignof(T));
			return new(memory) T();
		}
Example #5
0
		T* create(Args && ... args) {
			auto memory = memoryManager->allocate(sizeof(T), alignof(T));
			return new(memory) T(std::forward<Args>(args) ...);
		}