Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
patch for Windows PHP to analyze memory allocation
--- zend_alloc.c.org Wed Oct 17 18:21:42 2012
+++ zend_alloc.c Sun Nov 04 22:56:22 2012
@@ -263,17 +263,29 @@
static zend_mm_segment* zend_mm_mem_win32_alloc(zend_mm_storage *storage, size_t size)
{
- return (zend_mm_segment*) HeapAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, size);
+ zend_mm_segment* segment;
+
+ segment = (zend_mm_segment*) HeapAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, size);
+ fprintf(stderr, "[alloc] segment: 0x%lp-0x%lp size: %ld (%dMB)\n",
+ segment, ((char*) segment) + size - 1, size, size / 1024 / 1024);
+ return segment;
}
static void zend_mm_mem_win32_free(zend_mm_storage *storage, zend_mm_segment* segment)
{
+ fprintf(stderr, "[free] segment: 0x%lp\n", segment);
HeapFree((HANDLE)storage->data, HEAP_NO_SERIALIZE, segment);
}
static zend_mm_segment* zend_mm_mem_win32_realloc(zend_mm_storage *storage, zend_mm_segment* segment, size_t size)
{
- return (zend_mm_segment*) HeapReAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, segment, size);
+ zend_mm_segment* new_segment;
+
+ fprintf(stderr, "[realloc from] segment: 0x%lp\n", segment);
+ new_segment = (zend_mm_segment*) HeapReAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, segment, size);
+ fprintf(stderr, "[realloc to] segment: 0x%lp-0x%lp size: %ld (%dMB)\n",
+ new_segment, ((char*) new_segment) + size - 1, size, size / 1024 / 1024);
+ return new_segment;
}
# define ZEND_MM_MEM_WIN32_DSC {"win32", zend_mm_mem_win32_init, zend_mm_mem_win32_dtor, zend_mm_mem_win32_compact, zend_mm_mem_win32_alloc, zend_mm_mem_win32_realloc, zend_mm_mem_win32_free}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.