Click here to Skip to main content
15,906,625 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Libraries Pin
jhwurmbach11-Sep-03 1:16
jhwurmbach11-Sep-03 1:16 
GeneralRe: Libraries Pin
Zizilamoroso11-Sep-03 2:08
Zizilamoroso11-Sep-03 2:08 
GeneralRe: Libraries Pin
jhwurmbach11-Sep-03 2:10
jhwurmbach11-Sep-03 2:10 
GeneralDialog Help Pin
10-Sep-03 23:23
suss10-Sep-03 23:23 
GeneralRe: Dialog Help Pin
Iain Clarke, Warrior Programmer10-Sep-03 23:44
Iain Clarke, Warrior Programmer10-Sep-03 23:44 
GeneralSDI linkage with dialog Pin
coda_x10-Sep-03 23:21
coda_x10-Sep-03 23:21 
GeneralHorrid Memory Management Issue Pin
Dangleberry10-Sep-03 22:30
sussDangleberry10-Sep-03 22:30 
GeneralRe: Horrid Memory Management Issue Pin
Phil Speller10-Sep-03 23:20
Phil Speller10-Sep-03 23:20 
Well, first off, I've gotta say thanks - I learnt a new thing today - I was never aware of the placement syntax :/

Mixing C-style and C++ style memory allocations is not a good idea since they use separate memory managers. You could replace your malloc(sizeof(T)) with new char[sizeof(T)]. Realloc would still present you with the copying problem - infact, if realloc can't extend the memory area it will create a completely new area and perform a copy operation.

It does look like the placement syntax enables you to give an explicit address for the object you wish to dynamically create - it also looks like that will remove the overhead of the memory manager actually finding a suitable sized piece of free memory. So, I am thinking you are on the right track here.

[EDIT]
One thing I forgot to mention was that when you do use placement new, Stroustrup states that you need to explicitly call destructors for objects when you want to delete them - this makes sense since the memory manager is being bypassed.
[/EDIT]

However, you may want to consider creating space for several objects each time you need to reserve space i.e. new char[N*sizeof(T)]. Now create you own memory management scheme that uses that pool of memory with placement new. When that area is exhausted, create another pool. This has the effect of reducing the number of times the standard new operator needs to be called - thus reducing overhead. Ok, you have to manage each pool but working with fixed sized objects within each pool should be fairly efficient to to. There is a book called "Efficient C++" which looks at these issues in some detail.

Hope this helps




Phil
GeneralRe: Horrid Memory Management Issue Pin
Dangleberry10-Sep-03 23:59
sussDangleberry10-Sep-03 23:59 
GeneralRe: Horrid Memory Management Issue Pin
Phil Speller11-Sep-03 1:37
Phil Speller11-Sep-03 1:37 
GeneralRe: Horrid Memory Management Issue Pin
Dangleberry11-Sep-03 2:31
sussDangleberry11-Sep-03 2:31 
GeneralRe: Horrid Memory Management Issue Pin
Phil Speller10-Sep-03 23:50
Phil Speller10-Sep-03 23:50 
GeneralRe: Horrid Memory Management Issue Pin
Dangleberry11-Sep-03 0:14
sussDangleberry11-Sep-03 0:14 
GeneralRe: Horrid Memory Management Issue Pin
antlers11-Sep-03 9:39
antlers11-Sep-03 9:39 
GeneralRe: Horrid Memory Management Issue Pin
Dangleberry11-Sep-03 23:15
sussDangleberry11-Sep-03 23:15 
GeneralProblem handling pictures Pin
abhi197110-Sep-03 22:19
abhi197110-Sep-03 22:19 
GeneralRe: Problem handling pictures Pin
Dangleberry10-Sep-03 22:37
sussDangleberry10-Sep-03 22:37 
GeneralRe: Problem handling pictures Pin
abhi197110-Sep-03 22:51
abhi197110-Sep-03 22:51 
GeneralRe: Problem handling pictures Pin
Dangleberry10-Sep-03 22:58
sussDangleberry10-Sep-03 22:58 
GeneralRe: Problem handling pictures Pin
abhi197110-Sep-03 23:02
abhi197110-Sep-03 23:02 
GeneralRe: Problem handling pictures Pin
Dangleberry10-Sep-03 23:41
sussDangleberry10-Sep-03 23:41 
GeneralRe: Problem handling pictures Pin
Jagadeesh VN11-Sep-03 4:51
Jagadeesh VN11-Sep-03 4:51 
GeneralRe: Problem handling pictures Pin
abhi197111-Sep-03 22:36
abhi197111-Sep-03 22:36 
GeneralSocket programming in Visual C++ 6 Pin
fahimtufaillara10-Sep-03 21:55
fahimtufaillara10-Sep-03 21:55 
GeneralRe: Socket programming in Visual C++ 6 Pin
R. Thomas10-Sep-03 22:11
R. Thomas10-Sep-03 22:11 

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.