diff --git a/ChangeLog b/ChangeLog index 836337398..81f310a91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,10 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix memory allocation issue (virtual addres space waste) on windows + +0.16.11 release + * fix web seed URL double escape issue * fix string encoding issue in alert messages * fix SSL authentication issue diff --git a/src/allocator.cpp b/src/allocator.cpp index 2161dc38c..8268250b8 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -44,8 +44,8 @@ POSSIBILITY OF SUCH DAMAGE. #include // _SC_PAGESIZE #endif -#if TORRENT_USE_MEMALIGN || TORRENT_USE_POSIX_MEMALIGN -#include // memalign +#if TORRENT_USE_MEMALIGN || TORRENT_USE_POSIX_MEMALIGN || defined TORRENT_WINDOWS +#include // memalign and _aligned_malloc #endif #ifdef TORRENT_DEBUG_BUFFERS @@ -90,6 +90,8 @@ namespace libtorrent char* page_aligned_allocator::malloc(size_type bytes) { + TORRENT_ASSERT(bytes >= page_size()); + TORRENT_ASSERT(bytes % page_size() == 0); #ifdef TORRENT_DEBUG_BUFFERS int page = page_size(); int num_pages = (bytes + (page-1)) / page + 2; @@ -115,7 +117,7 @@ namespace libtorrent #elif TORRENT_USE_MEMALIGN return (char*)memalign(page_size(), bytes); #elif defined TORRENT_WINDOWS - return (char*)VirtualAlloc(0, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); + return (char*)_aligned_malloc(bytes, page_size()); #elif defined TORRENT_BEOS void* ret = 0; area_id id = create_area("", &ret, B_ANY_ADDRESS @@ -149,7 +151,7 @@ namespace libtorrent #endif #ifdef TORRENT_WINDOWS - VirtualFree(block, 0, MEM_RELEASE); + _aligned_free(block); #elif defined TORRENT_BEOS area_id id = area_for(block); if (id < B_OK) return;