0

what is the difference between memory allocated by GlobalAlloc & memory allocated by new .
is GlobalAlloc used in C++ or is it for C?
:)

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by CppBuilder2006
Featured Replies
  • 2
    Salem 5,138   7 Years Ago

    > when I deal with clipboard, I have to use GlobalAlloc. Because it tells you to in the manual pages perhaps? If the API's you're using have special requirements which mean you MUST use GlobalAlloc's special properties, then that is what you must use. If you're just writing standard C++, … Read More

  • 2
    WaltP 2,905   7 Years Ago

    [QUOTE=CppBuilder2006;1093535]when I deal with clipboard, I [U]have to[/U] use GlobalAlloc.[/quote] That makes sense. [ICODE]new[/ICODE] allocates within the realm of the program. Once the program exits, the memory is released. The clipboard then cleared (or broken). [ICODE]GlobalAlloc[/ICODE], I assume, leaves the allocated memory until the system clears it. [QUOTE=CppBuilder2006;1093535]is it recommended … Read More

0

No, GlobalAlloc is something unique to various windows platforms (search MSDN for it).

new is the standard C++ way to allocate memory.
Further, new also ensures that constructors get called to initialise the objects correctly.

1

How any commercial compiler manufacturer implements the C++ keyword 'new' is likely proprietary information, I expect. GlobalAlloc is of course unique to Win32. Its a function callable from any language capable of calling external functions. I use it a lot in PowerBASIC. I also use it in C and C++. So I wouldn't say the issue is unique to any language wheter C family or not. Of course you realize GlobalAlloc() isn't portable whereas new is - at least in the C++ world.

Yes, like Salem said, the differences between basic memory allocation functions (there are a lot of them in Win32) and the 'new' C++ operator is that 'new' does things very specific to the inner workings and logic of the C++ language relating to the operations of classes in terms of constructors and destructors, whereas basic memory allocation functions just give you a consequitive array of bytes.

Edited by Frederick2: n/a

0

when I deal with clipboard, I have to use GlobalAlloc.
is it recommended to use GobalAlloc where new can be used without problem (in Windows programming)?

2

> when I deal with clipboard, I have to use GlobalAlloc.
Because it tells you to in the manual pages perhaps?

If the API's you're using have special requirements which mean you MUST use GlobalAlloc's special properties, then that is what you must use.

If you're just writing standard C++, then use new.

2

when I deal with clipboard, I have to use GlobalAlloc.

That makes sense. new allocates within the realm of the program. Once the program exits, the memory is released. The clipboard then cleared (or broken). GlobalAlloc , I assume, leaves the allocated memory until the system clears it.

is it recommended to use GobalAlloc where new can be used without problem (in Windows programming)?

No.

Comments
convincing
0

new allocates within the realm of the program

so if I use GlobalAlloc to allocate memory, all programs will have it in common. programs can cooperate then...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.