Click here to Skip to main content
15,891,253 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCreateDIBSection Pin
pépé24-Sep-02 3:47
pépé24-Sep-02 3:47 
GeneralRe: CreateDIBSection Pin
Tomasz Sowinski24-Sep-02 3:56
Tomasz Sowinski24-Sep-02 3:56 
GeneralRe: CreateDIBSection Pin
pépé24-Sep-02 4:07
pépé24-Sep-02 4:07 
GeneralRe: CreateDIBSection Pin
Tomasz Sowinski24-Sep-02 4:14
Tomasz Sowinski24-Sep-02 4:14 
GeneralRe: CreateDIBSection Pin
pépé24-Sep-02 4:32
pépé24-Sep-02 4:32 
Generaldeleting strings Pin
Zizilamoroso24-Sep-02 3:42
Zizilamoroso24-Sep-02 3:42 
GeneralRe: deleting strings Pin
Tomasz Sowinski24-Sep-02 3:54
Tomasz Sowinski24-Sep-02 3:54 
GeneralRe: deleting strings Pin
John Burton24-Sep-02 3:54
John Burton24-Sep-02 3:54 
You can't.
Well, not without keeping some extra information anywhere.

Really this is a design problem, not an implementation problem - it's good practice to allocate and free memory at the same level of a program, so that level already knows how it allocated the memory.

For example

char* str = new char[100];
somefunction(str);
delete[] str;

char* str = "Hello world";
somefunction(str);
// No need to delete anything

The point is that "somefunction" didn't allocate the memory so it can't know how to free it and shouldn't try.

Basically whenever you allocate some memory you need to think about how it's going to be freed, and ensure that it's done at the same level as it was allocated, which is probably the only place that knows how to do it.
GeneralRe: deleting strings Pin
Le centriste24-Sep-02 6:50
Le centriste24-Sep-02 6:50 
GeneralRe: deleting strings Pin
Andreas Saurwein24-Sep-02 6:51
Andreas Saurwein24-Sep-02 6:51 
GeneralRe: deleting strings Pin
Zizilamoroso24-Sep-02 13:03
Zizilamoroso24-Sep-02 13:03 
GeneralRe: deleting strings Pin
Todd Smith24-Sep-02 7:13
Todd Smith24-Sep-02 7:13 
Generalprinting content in the specified position on document to printer Pin
vgkotha24-Sep-02 3:40
vgkotha24-Sep-02 3:40 
GeneralRe: printing content in the specified position on document to printer Pin
Roger Allen24-Sep-02 6:58
Roger Allen24-Sep-02 6:58 
QuestionError when use IDiskQuotaControl->FindUserName etc.? Pin
Anonymous24-Sep-02 3:38
Anonymous24-Sep-02 3:38 
Generalannoying carchive problem Pin
carrie24-Sep-02 3:16
carrie24-Sep-02 3:16 
Generaldeleting a control from the form Pin
ns24-Sep-02 3:14
ns24-Sep-02 3:14 
GeneralRe: deleting a control from the form Pin
jmkhael24-Sep-02 3:15
jmkhael24-Sep-02 3:15 
GeneralRe: deleting a control from the form Pin
ns24-Sep-02 3:47
ns24-Sep-02 3:47 
GeneralRe: deleting a control from the form Pin
jhwurmbach24-Sep-02 4:02
jhwurmbach24-Sep-02 4:02 
GeneralRe: deleting a control from the form Pin
Tomasz Sowinski24-Sep-02 4:10
Tomasz Sowinski24-Sep-02 4:10 
GeneralRe: deleting a control from the form Pin
Pavel Klocek24-Sep-02 4:10
Pavel Klocek24-Sep-02 4:10 
Generalsendmessage to a modal dialog Pin
ns24-Sep-02 2:32
ns24-Sep-02 2:32 
GeneralRe: sendmessage to a modal dialog Pin
jmkhael24-Sep-02 2:32
jmkhael24-Sep-02 2:32 
Generalthank you! Pin
ns24-Sep-02 2:41
ns24-Sep-02 2:41 

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.