Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
xpath_allocator Struct Reference

Public Member Functions

 xpath_allocator (xpath_memory_block *root, bool *error=0)
void * allocate (size_t size)
void * reallocate (void *ptr, size_t old_size, size_t new_size)
void revert (const xpath_allocator &state)
void release ()

Public Attributes

xpath_memory_block_root
size_t _root_size
bool * _error

Detailed Description

Definition at line 7768 of file pugixml.cc.

Constructor & Destructor Documentation

◆ xpath_allocator()

xpath_allocator::xpath_allocator ( xpath_memory_block * root,
bool * error = 0 )
inline

Definition at line 7774 of file pugixml.cc.

7774 : _root(root), _root_size(0), _error(error)
7775 {
7776 }
xpath_memory_block * _root
Definition pugixml.cc:7770
size_t _root_size
Definition pugixml.cc:7771

Referenced by revert().

Member Function Documentation

◆ allocate()

void * xpath_allocator::allocate ( size_t size)
inline

Definition at line 7778 of file pugixml.cc.

7779 {
7780 // round size up to block alignment boundary
7781 size = (size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7782
7783 if (_root_size + size <= _root->capacity)
7784 {
7785 void* buf = &_root->data[0] + _root_size;
7786 _root_size += size;
7787 return buf;
7788 }
7789 else
7790 {
7791 // make sure we have at least 1/4th of the page free after allocation to satisfy subsequent allocation requests
7792 size_t block_capacity_base = sizeof(_root->data);
7793 size_t block_capacity_req = size + block_capacity_base / 4;
7794 size_t block_capacity = (block_capacity_base > block_capacity_req) ? block_capacity_base : block_capacity_req;
7795
7796 size_t block_size = block_capacity + offsetof(xpath_memory_block, data);
7797
7798 xpath_memory_block* block = static_cast<xpath_memory_block*>(xml_memory::allocate(block_size));
7799 if (!block)
7800 {
7801 if (_error) *_error = true;
7802 return 0;
7803 }
7804
7805 block->next = _root;
7806 block->capacity = block_capacity;
7807
7808 _root = block;
7809 _root_size = size;
7810
7811 return block->data;
7812 }
7813 }
static allocation_function allocate
Definition pugixml.cc:199
char data[xpath_memory_page_size]
Definition pugixml.cc:7763
xpath_memory_block * next
Definition pugixml.cc:7758

Referenced by convert_number_to_string(), xpath_ast_node::eval_string_concat(), xpath_node_set_raw::remove_duplicates(), and translate_table_generate().

◆ reallocate()

void * xpath_allocator::reallocate ( void * ptr,
size_t old_size,
size_t new_size )
inline

Definition at line 7815 of file pugixml.cc.

7816 {
7817 // round size up to block alignment boundary
7818 old_size = (old_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7819 new_size = (new_size + xpath_memory_block_alignment - 1) & ~(xpath_memory_block_alignment - 1);
7820
7821 // we can only reallocate the last object
7822 assert(ptr == 0 || static_cast<char*>(ptr) + old_size == &_root->data[0] + _root_size);
7823
7824 // try to reallocate the object inplace
7825 if (ptr && _root_size - old_size + new_size <= _root->capacity)
7826 {
7827 _root_size = _root_size - old_size + new_size;
7828 return ptr;
7829 }
7830
7831 // allocate a new block
7832 void* result = allocate(new_size);
7833 if (!result) return 0;
7834
7835 // we have a new block
7836 if (ptr)
7837 {
7838 // copy old data (we only support growing)
7839 assert(new_size >= old_size);
7840 memcpy(result, ptr, old_size);
7841
7842 // free the previous page if it had no other objects
7843 assert(_root->data == result);
7844 assert(_root->next);
7845
7846 if (_root->next->data == ptr)
7847 {
7848 // deallocate the whole page, unless it was the first one
7849 xpath_memory_block* next = _root->next->next;
7850
7851 if (next)
7852 {
7854 _root->next = next;
7855 }
7856 }
7857 }
7858
7859 return result;
7860 }
allocation_function xml_memory_management_function_storage< T >::allocate
Definition pugixml.cc:205
static deallocation_function deallocate
Definition pugixml.cc:200

Referenced by xpath_node_set_raw::append(), xpath_string::append(), and xpath_node_set_raw::push_back_grow().

◆ release()

void xpath_allocator::release ( )
inline

Definition at line 7881 of file pugixml.cc.

7882 {
7883 xpath_memory_block* cur = _root;
7884 assert(cur);
7885
7886 while (cur->next)
7887 {
7888 xpath_memory_block* next = cur->next;
7889
7891
7892 cur = next;
7893 }
7894 }

Referenced by xpath_query_impl::destroy().

◆ revert()

void xpath_allocator::revert ( const xpath_allocator & state)
inline

Definition at line 7862 of file pugixml.cc.

7863 {
7864 // free all new pages
7865 xpath_memory_block* cur = _root;
7866
7867 while (cur != state._root)
7868 {
7869 xpath_memory_block* next = cur->next;
7870
7872
7873 cur = next;
7874 }
7875
7876 // restore state
7877 _root = state._root;
7878 _root_size = state._root_size;
7879 }

Member Data Documentation

◆ _error

bool* xpath_allocator::_error

Definition at line 7772 of file pugixml.cc.

Referenced by allocate(), and xpath_allocator().

◆ _root

xpath_memory_block* xpath_allocator::_root

Definition at line 7770 of file pugixml.cc.

Referenced by allocate(), reallocate(), release(), revert(), and xpath_allocator().

◆ _root_size

size_t xpath_allocator::_root_size

Definition at line 7771 of file pugixml.cc.

Referenced by allocate(), reallocate(), revert(), and xpath_allocator().


The documentation for this struct was generated from the following file: