Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.system > #265
| From | Alex Vinokur <alex.vinokur@gmail.com> |
|---|---|
| Newsgroups | comp.os.linux.development.system, comp.unix.programmer |
| Subject | [Linux] malloc: small size - small pointer? |
| Date | 2011-09-13 01:17 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <c36c7bc2-537d-4f24-976f-c08d61e06bb6@w12g2000yqa.googlegroups.com> (permalink) |
Cross-posted to 2 groups.
Hi,
Linux 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64
x86_64 x86_64 GNU/Linux
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on
Intel(R) 64, Version 12.0.4.191 Build 20110427
malloc() returns "small" pointers for small sizes.
Any suugestions for such behavior of the malloc function.
Are "small" pointers on heap?
------- Program foo.cpp -------
#include <stdio.h>
#include <stdlib.h>
#define SHOW(s_i_z_e, p_o_i_n_t_e_r) printf ("Size = 0x%lx, Pointer =
%p\n", s_i_z_e, p_o_i_n_t_e_r)
int main()
{
size_t size = 0x1ffe0;
void* pointer = 0;
for (size_t i = 0; i < 0x10; i++)
{
pointer = malloc(size);
SHOW(size, pointer);
size++;
}
return 0;
}
-------------------------------
Compilation:
> icpc foo.cpp
Running:
> ./a.out
Size = 0x1ffe0, Pointer = 0x199cc010
Size = 0x1ffe1, Pointer = 0x199ec000
Size = 0x1ffe2, Pointer = 0x19a0bff0
Size = 0x1ffe3, Pointer = 0x19a2bfe0
Size = 0x1ffe4, Pointer = 0x19a4bfd0
Size = 0x1ffe5, Pointer = 0x19a6bfc0
Size = 0x1ffe6, Pointer = 0x19a8bfb0
Size = 0x1ffe7, Pointer = 0x19aabfa0
Size = 0x1ffe8, Pointer = 0x19acbf90
Size = 0x1ffe9, Pointer = 0x19aebf80
Size = 0x1ffea, Pointer = 0x2ae67b770010
Size = 0x1ffeb, Pointer = 0x2ae67b791010
Size = 0x1ffec, Pointer = 0x2ae67b7b2010
Size = 0x1ffed, Pointer = 0x2ae67b7d3010
Size = 0x1ffee, Pointer = 0x2ae67b7f4010
Size = 0x1ffef, Pointer = 0x2ae67b815010
Alex
Back to comp.os.linux.development.system | Previous | Next — Next in thread | Find similar
[Linux] malloc: small size - small pointer? Alex Vinokur <alex.vinokur@gmail.com> - 2011-09-13 01:17 -0700
Re: [Linux] malloc: small size - small pointer? Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2011-09-13 10:23 +0200
Re: malloc: small size - small pointer? Alex Vinokur <alex.vinokur@gmail.com> - 2011-09-13 23:21 -0700
Re: malloc: small size - small pointer? Alex Vinokur <alex.vinokur@gmail.com> - 2011-09-13 23:18 -0700
Re: malloc: small size - small pointer? Alex Vinokur <alex.vinokur@gmail.com> - 2011-09-14 00:08 -0700
Re: [Linux] malloc: small size - small pointer? Kaz Kylheku <kaz@kylheku.com> - 2011-12-24 06:56 +0000
csiph-web