Click here to Skip to main content
15,884,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Memory deallocation Pin
Aescleal2-Feb-11 4:49
Aescleal2-Feb-11 4:49 
GeneralRe: Memory deallocation Pin
csrss2-Feb-11 5:21
csrss2-Feb-11 5:21 
GeneralRe: Memory deallocation Pin
Aescleal2-Feb-11 5:54
Aescleal2-Feb-11 5:54 
GeneralRe: Memory deallocation Pin
csrss2-Feb-11 6:16
csrss2-Feb-11 6:16 
Answer... [modified] Pin
csrss2-Feb-11 6:46
csrss2-Feb-11 6:46 
GeneralRe: ... Pin
Andrew Brock2-Feb-11 16:54
Andrew Brock2-Feb-11 16:54 
GeneralRe: ... Pin
csrss2-Feb-11 22:41
csrss2-Feb-11 22:41 
AnswerRe: Memory deallocation Pin
Stefan_Lang3-Feb-11 6:38
Stefan_Lang3-Feb-11 6:38 
There are two possible solutions:

1. If the data structure in question is trivial and can be trivially allocated and deallocated, delegate the allocation to the caller. this is what many standard functions such as strcpy() do.

2. If the data structure requires some attention upon allocation, or contains arrays of dynamical (and potentially at the time of creation unknown) length, then the above suggested method is preferable, i. e. you allocate the structure and provide a function to deallocate it appropriately at a later time.

Personally I prefere the first method whereever possible, because it is clearer from the point of view of the caller: it is much easier to spot a missing delete or free that should have been paired with a new or malloc, than spotting a missing call to a deallocation function which should be paired with some "get" or "read" function. It may not be implicitely clear that a function that provides some data also allocates the structure (it might just as well provide a pointer to a structure that is allocated and accordingly freed elsewhere!)
Question[REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Curtis Tong1-Feb-11 23:38
Curtis Tong1-Feb-11 23:38 
GeneralRe: [REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Malli_S1-Feb-11 23:57
Malli_S1-Feb-11 23:57 
AnswerRe: [REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Malli_S2-Feb-11 0:04
Malli_S2-Feb-11 0:04 
GeneralRe: [REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Andrew Brock2-Feb-11 0:51
Andrew Brock2-Feb-11 0:51 
GeneralRe: [REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Malli_S2-Feb-11 0:57
Malli_S2-Feb-11 0:57 
AnswerRe: [REQUEST] TabControl Sample Code (Visual C++, Win32, Win32 Project) with Tutorial on what to edit to customize it Pin
Andrew Brock2-Feb-11 0:51
Andrew Brock2-Feb-11 0:51 
QuestionSong and video Parsing Pin
VikramRathod1-Feb-11 22:30
VikramRathod1-Feb-11 22:30 
AnswerRe: Song and video Parsing Pin
Cedric Moonen1-Feb-11 23:12
Cedric Moonen1-Feb-11 23:12 
AnswerRe: Song and video Parsing Pin
Emilio Garavaglia2-Feb-11 1:59
Emilio Garavaglia2-Feb-11 1:59 
JokeRe: Song and video Parsing Pin
Cool_Dev2-Feb-11 2:16
Cool_Dev2-Feb-11 2:16 
GeneralRe: Song and video Parsing Pin
VikramRathod10-Feb-11 20:15
VikramRathod10-Feb-11 20:15 
Questionhow do i sync two places.sqlite..? Pin
yogish2931-Feb-11 19:58
yogish2931-Feb-11 19:58 
AnswerRe: how do i sync two places.sqlite..? Pin
User 74293381-Feb-11 20:13
professionalUser 74293381-Feb-11 20:13 
GeneralRe: how do i sync two places.sqlite..? Pin
yogish2931-Feb-11 20:17
yogish2931-Feb-11 20:17 
AnswerRe: how do i sync two places.sqlite..? Pin
Niklas L1-Feb-11 21:20
Niklas L1-Feb-11 21:20 
QuestionHow to add a tag like //<AMRIT.AGRAWAL> Added 02/02/2011 on a shortcut key in somewhere in the code Pin
Amrit Agr1-Feb-11 19:37
Amrit Agr1-Feb-11 19:37 
AnswerRe: How to add a tag like // Added 02/02/2011 on a shortcut key in somewhere in the code Pin
_AnsHUMAN_ 1-Feb-11 19:59
_AnsHUMAN_ 1-Feb-11 19:59 

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.