MCPcopy Create free account
hub / github.com/WheretIB/nullc / allocate_string

Method allocate_string

external/pugixml/pugixml.cpp:317–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

315 }
316
317 char_t* allocate_string(size_t length)
318 {
319 // allocate memory for string and header block
320 size_t size = sizeof(xml_memory_string_header) + length * sizeof(char_t);
321
322 // round size up to pointer alignment boundary
323 size_t full_size = (size + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1);
324
325 xml_memory_page* page;
326 xml_memory_string_header* header = static_cast<xml_memory_string_header*>(allocate_memory(full_size, page));
327
328 if (!header) return 0;
329
330 // setup header
331 ptrdiff_t page_offset = reinterpret_cast<char*>(header) - page->data;
332
333 assert(page_offset >= 0 && page_offset < (1 << 16));
334 header->page_offset = static_cast<uint16_t>(page_offset);
335
336 // full_size == 0 for large strings that occupy the whole page
337 assert(full_size < (1 << 16) || (page->busy_size == full_size && page_offset == 0));
338 header->full_size = static_cast<uint16_t>(full_size < (1 << 16) ? full_size : 0);
339
340 return reinterpret_cast<char_t*>(header + 1);
341 }
342
343 void deallocate_string(char_t* string)
344 {

Callers 1

strcpy_insituFunction · 0.80

Calls 1

assertFunction · 0.85

Tested by

no test coverage detected