www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Using new to allocate memory in Win32

reply Dan Rushe <thecourtjesture advnet.net> writes:
    Does DM implement the new operator when compiling Win32 apps?  And
if so, how does it work.  Returning a pointer to an object is useless
under Windows, especially when memory gets moved around.  So, if new
returns a pointer to the object, how could you possibly use it with
Windows?

    I had Borland C++ 4.5, and the documentation said that it contained
a heap manager, but it did not say how the pointers could be resolved.
Any help would be appreciated.

--
            Dan Rushe
            thecourtjesture advnet.net

Aug 06 2001
next sibling parent Jan Knepper <jan smartsoft.cc> writes:
Dan Rushe wrote:

     Does DM implement the new operator when compiling Win32 apps?
Yes it does.
 And if so, how does it work.  Returning a pointer to an object is useless

 under Windows, especially when memory gets moved around.  So, if new
 returns a pointer to the object, how could you possibly use it with
 Windows?
DMC++ has a very efficient memory management implementation which calls VirtualAlloc at the lowest level of the 'operator new' implementation as far as I know. VirtualAlloc is being called with MEM_COMMIT and PAGE_READWRITE if that is of any help. Jan
Aug 06 2001
prev sibling next sibling parent reply "Walter" <walter digitalmars.com> writes:
The memory moving around was a problem in real mode windows, which was
dumped by Microsoft by Windows version 3.1 (as I recall). This is not an
issue in protected mode Windows, available from Windows 3.0 on.

Dan Rushe wrote in message <3B6F1488.DF237A17 advnet.net>...
    Does DM implement the new operator when compiling Win32 apps?  And
if so, how does it work.  Returning a pointer to an object is useless
under Windows, especially when memory gets moved around.  So, if new
returns a pointer to the object, how could you possibly use it with
Windows?

    I had Borland C++ 4.5, and the documentation said that it contained
a heap manager, but it did not say how the pointers could be resolved.
Any help would be appreciated.

--
            Dan Rushe
            thecourtjesture advnet.net

Aug 06 2001
parent reply Dan Rushe <thecourtjesture advnet.net> writes:
Walter wrote:

 The memory moving around was a problem in real mode windows, which was
 dumped by Microsoft by Windows version 3.1 (as I recall). This is not an
 issue in protected mode Windows, available from Windows 3.0 on.
So memory does not move around anymore? And if not, then the pointers should remain valid. The reason I need to know, is that I'm trying to implement a linked list in Windows, and I wasn't impressed with using handles to memory blocks for each item. -- Dan Rushe thecourtjesture advnet.net
Aug 07 2001
next sibling parent Jan Knepper <jan smartsoft.cc> writes:
The handles in Win32 are actually pointers...



Dan Rushe wrote:

 Walter wrote:

 The memory moving around was a problem in real mode windows, which was
 dumped by Microsoft by Windows version 3.1 (as I recall). This is not an
 issue in protected mode Windows, available from Windows 3.0 on.
So memory does not move around anymore? And if not, then the pointers should remain valid. The reason I need to know, is that I'm trying to implement a linked list in Windows, and I wasn't impressed with using handles to memory blocks for each item.
Aug 07 2001
prev sibling next sibling parent reply "Walter" <walter digitalmars.com> writes:
Dan Rushe wrote in message <3B70034E.15A4BD8E advnet.net>...
Walter wrote:
 The memory moving around was a problem in real mode windows, which was
 dumped by Microsoft by Windows version 3.1 (as I recall). This is not an
 issue in protected mode Windows, available from Windows 3.0 on.
So memory does not move around anymore? And if not, then the pointers should remain valid. The reason I need to know, is that I'm trying to implement a linked list in Windows, and I wasn't impressed with using handles to memory blocks for each item.
They're just pointers now. A lot of documentation was written about real mode windows programming that never got updated to protected mode reality, so it's easy to get the impression you still need to worry about real mode issues.
Aug 07 2001
parent reply Jan Knepper <jan smartsoft.cc> writes:
 They're just pointers now. A lot of documentation was written about real
 mode windows programming that never got updated to protected mode reality,
 so it's easy to get the impression you still need to worry about real mode
 issues.
Just to confuse things a little more M$ did the following in winnt.h (used for all Win32 platforms): typedef void *PVOID; [ ... snip ... ] #ifdef STRICT typedef void *HANDLE; #define #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endif typedef HANDLE *PHANDLE; So basically a 'HANDLE' is 'void *' <g> Jan
Aug 07 2001
parent reply "Walter" <walter digitalmars.com> writes:
This kind of fiddling is why D has typechecking for typedef'd names.

Jan Knepper wrote in message <3B700A93.F41EFC25 smartsoft.cc>...
 They're just pointers now. A lot of documentation was written about real
 mode windows programming that never got updated to protected mode
reality,
 so it's easy to get the impression you still need to worry about real
mode
 issues.
Just to confuse things a little more M$ did the following in winnt.h (used
for
all Win32 platforms):

typedef void *PVOID;

[ ... snip ... ]

#ifdef STRICT
typedef void *HANDLE;
#define
struct

#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif
typedef HANDLE *PHANDLE;

So basically a 'HANDLE' is 'void *'
<g>

Jan
Aug 07 2001
parent reply Jan Knepper <jan smartsoft.cc> writes:
Have you done anything on 'D' lately?
To prepare I could begin creating a newsgroup 'd' <g>

Jan



Walter wrote:

 This kind of fiddling is why D has typechecking for typedef'd names.
Aug 07 2001
parent reply "Walter" <walter digitalmars.com> writes:
I'm working on it again...

Jan Knepper wrote in message <3B701B60.ACED67DE smartsoft.cc>...
Have you done anything on 'D' lately?
To prepare I could begin creating a newsgroup 'd' <g>

Jan



Walter wrote:

 This kind of fiddling is why D has typechecking for typedef'd names.
Aug 08 2001
parent reply "jacob navia" <jacob jacob.remcomp.fr> writes:
What is 'D' Walter?
Aug 17 2001
parent Jan Knepper <jan smartsoft.cc> writes:
Wow! You've missed some day yesterday!

http://www.digitalmars.com/D/

news://news.digitalmars.com/D

I guess we could say we were slashdotted yesterday...

Jan
Aug 17 2001
prev sibling parent reply "Rajiv Bhagwat" <dataflow vsnl.com> writes:
All the technical discussion simply means:
- go ahead with your linked list without any worries about memory moving.
Your pointers will NOT change on you without you doing so!! As far as the
programmers are concerned, the same linked list code should work for DOS,
Unix or current versions of Windows.

-- Rajiv Bhagwat


Dan Rushe <thecourtjesture advnet.net> wrote in message
news:3B70034E.15A4BD8E advnet.net...
 Walter wrote:

 The memory moving around was a problem in real mode windows, which was
 dumped by Microsoft by Windows version 3.1 (as I recall). This is not an
 issue in protected mode Windows, available from Windows 3.0 on.
So memory does not move around anymore? And if not, then the pointers should remain valid. The reason I need to know, is that I'm trying to implement a linked list in Windows, and I wasn't impressed with using handles to memory blocks for each item. -- Dan Rushe thecourtjesture advnet.net
Aug 07 2001
parent Jan Knepper <jan smartsoft.cc> writes:
Rajiv Bhagwat wrote:

 All the technical discussion simply means:
 - go ahead with your linked list without any worries about memory moving.
 Your pointers will NOT change on you without you doing so!! As far as the
 programmers are concerned, the same linked list code should work for DOS,
 Unix or current versions of Windows.
AMEN!
Aug 07 2001
prev sibling parent reply Dan Rushe <thecourtjesture advnet.net> writes:
    Thanks to everybody who wrote back, I really appreciate it.  I guess it
is now time to retire my Windows API Bible from 7 years back and get an
updated version!
--
            Dan Rushe
            thecourtjesture advnet.net

Aug 08 2001
parent reply Jan Knepper <jan smartsoft.cc> writes:
Dan Rushe wrote:

     Thanks to everybody who wrote back, I really appreciate it.  I guess it
 is now time to retire my Windows API Bible from 7 years back and get an
 updated version!
No Kidding!
Aug 08 2001
parent reply Dan Rushe <thecourtjesture advnet.net> writes:
Jan Knepper wrote:

 Dan Rushe wrote:

     Thanks to everybody who wrote back, I really appreciate it.  I guess it
 is now time to retire my Windows API Bible from 7 years back and get an
 updated version!
No Kidding!
Does anybody know of a good source of Win32 API information? As it turns out, I was trying to reinvent the wheel. I was working on a tree list control, but then I realized that Windows 9x already has one. -- Dan Rushe thecourtjesture advnet.net
Aug 09 2001
parent reply Jan Knepper <jan smartsoft.cc> writes:
Well, It's called MSDN I guess, you can buy it from M$...



Dan Rushe wrote:

 Jan Knepper wrote:

 Dan Rushe wrote:

     Thanks to everybody who wrote back, I really appreciate it.  I guess it
 is now time to retire my Windows API Bible from 7 years back and get an
 updated version!
No Kidding!
Does anybody know of a good source of Win32 API information? As it turns out, I was trying to reinvent the wheel. I was working on a tree list control, but then I realized that Windows 9x already has one.
Aug 09 2001
parent reply Dan Rushe <thecourtjesture advnet.net> writes:
Jan Knepper wrote:

 Well, It's called MSDN I guess, you can buy it from M$...
Damn, I was afraid you'd say that! Know of any good books? -- Dan Rushe thecourtjesture advnet.net
Aug 09 2001
parent reply Jan Knepper <jan smartsoft.cc> writes:
Dan Rushe wrote:

 Jan Knepper wrote:
 Well, It's called MSDN I guess, you can buy it from M$...
Damn, I was afraid you'd say that! Know of any good books?
Well, I didn't like saying it... But hey, for Win32 and all the other cr*p that makes part of the alternative (M$) operating systems it's probably the best resource... Good books... Depends on what you want to do... Check digitalmars.com, there might be a reference to a book. Otherwise... Search for them on Amazon.com... Jan
Aug 09 2001
parent "Rajiv Bhagwat" <dataflow vsnl.com> writes:
I hope you subscribe to DDJ, CUJ, MSDN (MSJ), Window Developer atleast?
These mags contain some good articals on the practical aspects and are my
substitue to the MSDN subscription.

-- Rajiv Bhagwat


Jan Knepper <jan smartsoft.cc> wrote in message
news:3B7329C4.A6496892 smartsoft.cc...
 Dan Rushe wrote:

 Jan Knepper wrote:
 Well, It's called MSDN I guess, you can buy it from M$...
Damn, I was afraid you'd say that! Know of any good books?
Well, I didn't like saying it... But hey, for Win32 and all the other cr*p that makes part of the alternative (M$) operating systems it's probably the best resource... Good books... Depends on what you want to do... Check digitalmars.com, there might be a reference to a book. Otherwise... Search for them on Amazon.com... Jan
Aug 11 2001