Click here to Skip to main content
15,916,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Very slow function free() Pin
bschorre13-Oct-04 4:09
bschorre13-Oct-04 4:09 
GeneralRe: Very slow function free() Pin
David Crow13-Oct-04 4:11
David Crow13-Oct-04 4:11 
GeneralRe: Very slow function free() Pin
Blake Miller13-Oct-04 4:27
Blake Miller13-Oct-04 4:27 
GeneralRe: Very slow function free() Pin
bschorre14-Oct-04 1:49
bschorre14-Oct-04 1:49 
GeneralRe: Very slow function free() Pin
Mad__14-Oct-04 1:12
Mad__14-Oct-04 1:12 
GeneralRe: Very slow function free() Pin
bschorre14-Oct-04 1:46
bschorre14-Oct-04 1:46 
GeneralRe: Very slow function free() Pin
Mad__14-Oct-04 1:57
Mad__14-Oct-04 1:57 
GeneralRe: Very slow function free() Pin
Henry miller14-Oct-04 2:54
Henry miller14-Oct-04 2:54 
For what complier/C library? malloc/free is not provided by any OS I'm aware of. Instead your C library (which might come with the compiler, might be included) provides it.

In some Unix systems (and I suspect Windows as well), the library asks the OS for more memory than you requested, and then holds that in a buffer. If you malloc more, it will give you memroy from that same buffer if there is room. When you free the memory it marks it unused, but doesn't return it to the OS, instead it will hold onto it in case you need more memory latter.

On many systems the OS will only allow you to allocate 4Kb chunks (this varies depending on both the OS and the design of the hardware). The library is designed so that you can malloc a few bytes, without getting a full 4kb.

Also, in many cases the library will write something to most of that memory when it is allocated. The OS however may just mark your application as allowed to use that much memory, but not actually give it to you, until you use it.

In effect it is optimized for small accesses, and you are sending it a large acccess which it isn't designed for.

If you don't need portability you might be able to speed things up by using OS specific functions to get the memory from the OS yourself.

Note that none of this will help if you don't have enough physical memory. If you want to use 256M of memory you should have at least 400M of physical memory so the OS doesn't have page everything else out.
GeneralChange baudrate on opened serial port Pin
smaier3013-Oct-04 3:50
smaier3013-Oct-04 3:50 
GeneralRe: Change baudrate on opened serial port Pin
Vaclav13-Oct-04 6:05
Vaclav13-Oct-04 6:05 
GeneralRe: Change baudrate on opened serial port Pin
smaier3014-Oct-04 2:08
smaier3014-Oct-04 2:08 
Questioncreate winamp like visualization in wav player? Pin
V.G13-Oct-04 3:10
V.G13-Oct-04 3:10 
Generaldesign patterns - where to start Pin
BlackDice13-Oct-04 3:09
BlackDice13-Oct-04 3:09 
GeneralRe: design patterns - where to start Pin
David Crow13-Oct-04 3:11
David Crow13-Oct-04 3:11 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 3:15
BlackDice13-Oct-04 3:15 
GeneralRe: design patterns - where to start Pin
David Crow13-Oct-04 3:27
David Crow13-Oct-04 3:27 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 3:32
BlackDice13-Oct-04 3:32 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 3:41
BlackDice13-Oct-04 3:41 
GeneralRe: design patterns - where to start Pin
David Crow13-Oct-04 3:57
David Crow13-Oct-04 3:57 
GeneralRe: design patterns - where to start Pin
hyling13-Oct-04 4:27
hyling13-Oct-04 4:27 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 4:29
BlackDice13-Oct-04 4:29 
GeneralRe: design patterns - where to start Pin
Antony M Kancidrowski13-Oct-04 4:29
Antony M Kancidrowski13-Oct-04 4:29 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 4:34
BlackDice13-Oct-04 4:34 
GeneralRe: design patterns - where to start Pin
Kevin McFarlane13-Oct-04 6:26
Kevin McFarlane13-Oct-04 6:26 
GeneralRe: design patterns - where to start Pin
BlackDice13-Oct-04 7:36
BlackDice13-Oct-04 7:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.