Example #1
0
 void swap(ckernel_builder &rhs)
 {
   if (using_static_data()) {
     if (rhs.using_static_data()) {
       char tmp_static_data[sizeof(m_static_data)];
       memcpy(tmp_static_data, m_static_data, sizeof(m_static_data));
       memcpy(m_static_data, rhs.m_static_data, sizeof(m_static_data));
       memcpy(rhs.m_static_data, tmp_static_data, sizeof(m_static_data));
     } else {
       memcpy(rhs.m_static_data, m_static_data, sizeof(m_static_data));
       m_data = rhs.m_data;
       m_capacity = rhs.m_capacity;
       rhs.m_data = &rhs.m_static_data[0];
       rhs.m_capacity = 16 * sizeof(intptr_t);
     }
   } else {
     if (rhs.using_static_data()) {
       memcpy(m_static_data, rhs.m_static_data, sizeof(m_static_data));
       rhs.m_data = m_data;
       rhs.m_capacity = m_capacity;
       m_data = &m_static_data[0];
       m_capacity = sizeof(m_static_data);
     } else {
       (std::swap)(m_data, rhs.m_data);
       (std::swap)(m_capacity, rhs.m_capacity);
     }
   }
 }
Example #2
0
 inline void destroy()
 {
   if (m_data != NULL) {
     ckernel_prefix *self = reinterpret_cast<ckernel_prefix *>(m_data);
     // Destroy whatever was created
     self->destroy();
     if (!using_static_data()) {
       // Free the memory
       free(self);
     }
   }
 }
 void *realloc(void *ptr, size_t old_size, size_t new_size) {
   if (using_static_data()) {
     // If we were previously using the static data, do a malloc
     void *new_data = alloc(new_size);
     // If the allocation succeeded, copy the old data as the realloc would
     if (new_data != NULL) {
       copy(new_data, ptr, old_size);
     }
     return new_data;
   } else {
     return std::realloc(ptr, new_size);
   }
 }
 void free(void *ptr) {
   if (!using_static_data()) {
     std::free(ptr);
   }
 }
 ~storagebuf() {
   if (!using_static_data() && m_data != NULL) {
     free(m_data);
   }
 }