Click here to Skip to main content
15,886,689 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Getting the error Link2001: unresolved reference to the function Pin
Stefan_Lang3-Feb-11 21:29
Stefan_Lang3-Feb-11 21:29 
GeneralRe: Getting the error Link2001: unresolved reference to the function Pin
charanmanjunath3-Feb-11 22:36
charanmanjunath3-Feb-11 22:36 
GeneralRe: Getting the error Link2001: unresolved reference to the function Pin
charanmanjunath8-Feb-11 3:10
charanmanjunath8-Feb-11 3:10 
QuestionMemory deallocation Pin
csrss2-Feb-11 4:16
csrss2-Feb-11 4:16 
AnswerRe: Memory deallocation Pin
Stephen Hewitt2-Feb-11 4:26
Stephen Hewitt2-Feb-11 4:26 
AnswerRe: Memory deallocation Pin
Andrew Brock2-Feb-11 4:32
Andrew Brock2-Feb-11 4:32 
QuestionRe: Memory deallocation Pin
csrss2-Feb-11 4:53
csrss2-Feb-11 4:53 
AnswerRe: Memory deallocation Pin
Aescleal2-Feb-11 4:49
Aescleal2-Feb-11 4:49 
If you want to pass blocks of memory around between modules then make sure that whatever module allocated it also frees it. If you don't do that you might end up running into problems with memory being allocated by an allocator specific to one module being returned to another and things going wrong. This means in C calling free from the same library malloc was called from, in C++ it means calling delete from the same module that new was called from [1]. If you're mad enough to be using raw Win32 API calls then whatever called Heap/Global/Local/VirtualAlloc should call Heap/Global/Local/VirtualFree with any required Heap/Global/Local/Virtual[Un]Lock pairs.

There are some other strategies you can use to reduce the chance of an error. One is to write your library so that it doesn't do any memory management. You can do this by either making the client give the library a lump of memory to use or by making the client give a pair of function pointers (functor or interface in C++) to the library - one a pointer to an allocation function, another a poitner to a free/release function. I'd personally go for the first if I were doing cross language calls as the client code can allocate a lump of raw bytes from it's own runtime, give it to a library to play with and then when it's finished consign it to the big bit bucket in the sky. Oh, and make sure that the data structures you're using are plain old data (POD) as different languages have different ideas about what an object is. No idea about C# but Python, for example, can't use C++ objects (and vice versa) without writing a C interface for it.

[1] There are some exceptions - if you're a bit cunning you can get around this rule but it's a good first approximation to say "you allocated it, you release it."

Anyway, hope that helps a bit, if not please shout.

Cheers,

Ash
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 
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 

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.