From: Pavel Stehule on 31 Mar 2010 11:05 Hi, I playing with mmap. I have a problem with mremap function. It doesn't allocate correct memory. All others work well. static void * mmap_realloc(void *ptr, Size size) { Size oldsize; void *result; int i; char *x; ptr = (char *) ptr - MAXALIGN(sizeof(Size)); oldsize = *((Size *) ptr); size = MAXALIGN(size) + MAXALIGN(sizeof(Size)); ptr = mremap(ptr, oldsize, size, MREMAP_MAYMOVE); if (ptr == MAP_FAILED) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"), errdetail("Failed on request of size %lu.", (unsigned long) size))); *((Size*) ptr) = size; result = (char *) ptr + MAXALIGN(sizeof(Size)); /* check allocated memory */ x = ptr; fprintf(stderr, "allocated memory %ld\n", size); for (i = 0; i < size; i++) { if (i > oldsize) { *x = 0; } x++; } fprintf(stderr, "memory checked\n"); return result; } log: >>>> 1 <<<>>> 1048584 >>>> 3 <<<>>> 2097216 >>>> 3 <<<>>> 9024 allocated memory 10304 memory checked allocated memory 11584 memory checked allocated memory 12864 gdb Program terminated with signal 7, Bus error. #0 mmap_realloc (size=12864, ptr=<value optimized out>) at mmap_alloc.c:357 357 *x = 0; Missing separate debuginfos, use: debuginfo-install glibc-2.10.2-1.x86_64 (gdb) print x $1 = 0x7f92055df000 "" (gdb) print i $2 = 12289 Can somebody help me? Regards Pavel Stehule -- Sent via pgsql-hackers mailing list (pgsql-hackers(a)postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
|
Pages: 1 Prev: [HACKERS] pgindent excluded files list Next: pgindent excluded files list |