void CudaSynchronizedMemory<T>::reset() { m_size = 0; freeHostMemory(); freeDeviceMemory(); m_pageLocked = false; }
//------------------------------------------------------------------------ // ArenaAllocator::destroy: // Performs any necessary teardown for an `ArenaAllocator`. // // Notes: // This method walks from `m_firstPage` forward and releases the pages. // Be careful no other thread has called `reset` at the same time. // Otherwise, the page specified by `page` could be double-freed // (VSW 600919). void ArenaAllocator::destroy() { // Free all of the allocated pages for (PageDescriptor* page = m_firstPage, *next; page != nullptr; page = next) { next = page->m_next; freeHostMemory(page); } // Clear out the allocator's fields m_firstPage = nullptr; m_lastPage = nullptr; m_nextFreeByte = nullptr; m_lastFreeByte = nullptr; }
//------------------------------------------------------------------------ // ArenaAllocator::reset: // Resets the current position of an `ArenaAllocator` to the given // mark, freeing any unused pages. // // Arguments: // mark - The mark that stores the desired position for the allocator. // // Notes: // This method may walk the page list backward and release the pages. // Be careful no other thread is doing `destroy` as the same time. // Otherwise, the page specified by `temp` could be double-freed // (VSW 600919). void ArenaAllocator::reset(MarkDescriptor& mark) { // If the active page hasn't changed, just reset the position into the // page and return. if (m_lastPage == mark.m_page) { m_nextFreeByte = mark.m_next; m_lastFreeByte = mark.m_last; return; } // Otherwise, free any new pages that were added. void* last = mark.m_page; if (last == nullptr) { if (m_firstPage == nullptr) { return; } m_nextFreeByte = m_firstPage->m_contents; m_lastFreeByte = m_firstPage->m_pageBytes + (BYTE*)m_firstPage; return; } while (m_lastPage != last) { // Remove the last page from the end of the list PageDescriptor* temp = m_lastPage; m_lastPage = temp->m_previous; // The new last page has no next page m_lastPage->m_next = nullptr; freeHostMemory(temp); } m_nextFreeByte = mark.m_next; m_lastFreeByte = mark.m_last; }