Thread: RE: [Dev-C++] new is a wrapper around malloc so...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-07-15 18:48:50
|
In 16 bit your code is separated into 'segments' each a maximum of 64k in size. 32-bit can have up to 2GB segments (!!!). A 'near' pointer can access variables etc. within its own segment, while FAR pointers can access anything. Likewise a FAR variable can be accessed from anywhere (by a FAR pointer), while a NEAR one (the default) is local to that segment. Think of it like a telephone numbering system. My number is, say, 401234. But that is no good to you unless you live local to me. If you tried typing 401234 into the phone you'd not reach me if you lived far away. SO if I gave you my "FAR" number, it would be 01172 401234 and you would be able to reach me even if you were not local. This is how I understand NEAR and FAR. >From: "Ioannis Vranos" <iv...@em...> >To: <dev...@li...> >Subject: RE: [Dev-C++] new is a wrapper around malloc so... >Date: Tue, 15 Jul 2003 20:25:46 +0300 > > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf > > Of Daniel Glenfield > > Sent: Tuesday, July 15, 2003 10:13 AM > > To: dev...@li... > > Subject: [Dev-C++] new is a wrapper around malloc so... > > > > > > Hi guys, > > I'm writing some code for 16 bit and have code split into > > segments. This > > means I need to create a Far version of new, but I don't know > > much about > > malloc - can anyone show me what operator new looks like? > > >new is not a wrapper of malloc(). It is an entity of its own. In fact >malloc() should not be used in C++ because it does not call the object's >costructor. Also there is no guarantee that even for POD types new, delete >and the malloc() family,free() are interoperable. > >I do not know what a Far pointer, but I do know that they exist. Can you >tell us what does it mean? > > > >You can overide the operator new to define its functionality (e.g. to >provide space from an array of yours in the stack). It is what TC++PL names >"placement operator new". > > > > > > >Ioannis Vranos > >* Programming pages: http://www.noicys.freeurl.com >* Alternative URL 1: http://run.to/noicys >* Alternative URL 2: http://www.noicys.cjb.net > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Parasoft >Error proof Web apps, automate testing & more. >Download & eval WebKing and get a free book. >www.parasoft.com/bulletproofapps1 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Tired of 56k? Get a FREE BT Broadband connection http://www.msn.co.uk/specials/btbroadband |
|
From: Daniel G. <sp...@ho...> - 2003-07-15 19:00:06
|
Thanks. I'm trying to use the large memory model at the moment but it hasn't gotten rid of the need for FAR. Maybe I've done something wrong somewhere, I need to check. Windows 9x has 16 bit code in it in places, such as Printer Drivers and other bits. >From: "Abhijit Shylanath" <mu...@gm...> >To: "Ioannis Vranos" ><iv...@em...>,<dev...@li...>,<sp...@ho...> >Subject: RE: [Dev-C++] new is a wrapper around malloc so... >Date: Wed, 16 Jul 2003 00:07:20 +0530 > > >Hello, Ioannis and Daniel. > > > I do not know what a Far pointer, but I do know that they exist. Can you > > tell us what does it mean? > >Well, you must know that we have four basic segments (on the 8086) - the >CS, >DS, SS and ES... by default, when a data pointer is defined, it is assumed >that the pointer resides in the data segment, and when a function pointer >is >defined, that it resides in the code segment. However, when a pointer is >flagged as `far', it means that the segment is also stored explicitly along >with the offset. So, basically, far pointers allow you to access the whole >(and overwhelmingly huge) 1M of the 8086. Basically, far means residing in >a >different segment, while near means residing in the same (the default) >segment. > >Daniel, in response to your original question: > >Assuming you code in Turbo-C++, you have three options: > >1. Use a memory-model in which the required pointer's type is far by >default. If you need far data (the most common), use compact (in which the >data pointers are still near). If you need far code, use (umm, not sure, >really) large or huge (check the docs). You'll need to say something like >this: > char *foo = (char *)malloc(WHATEVER); > >2. Use the farmalloc() function (in TC - in M$C, I've heard that it's named >halloc()). Corresponding frees should be done by farfree() (dunno about >M$C). > > char far *foo = (char far *)farmalloc(WHATEVER); > // ... > farfree(foo); > >3. The easiest - simply call `new'. AFAIK, you don't need to overload new: > > char far *big_one = new char far[200]; > // ^? > // Play around a bit with the syntax, I'm not sure that this works... > > I remember doing something like this sometime back. > >However, why do you need to use different segments at all? You should try >porting it to 32-bit protected-mode DOS (or even Windows console-mode), if >your application allows it. Sad as it is for me to say it, DOS is dead. >Anyway, here are a few links you might find interesting: > >* http://www.delorie.com/djgpp > DJGPP - A DOS protected-mode C/++ compiler based on GCC > >* http://sunsite.lanet.lv/ftp/mirror/x2ftp/msdos/programming/ > The X2FTP - hordes of information on related topics. > >HTH. > >-- >Abhijit Shylanath >Homepage: http://mudeth.tripod.com/ > > > > >------------------------------------------------------- >This SF.Net email sponsored by: Parasoft >Error proof Web apps, automate testing & more. >Download & eval WebKing and get a free book. >www.parasoft.com/bulletproofapps1 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband |
|
From: Daniel G. <sp...@ho...> - 2003-07-16 09:04:57
|
All I know is that the MSDN documentation I read says 2GB. I'm not sure about how you calculate it all, so you're one up on me! >From: "Abhijit Shylanath" <mu...@gm...> >To: "Daniel Glenfield" <sp...@ho...> >CC: "Dev-Cpp mailing list" <dev...@li...> >Subject: RE: [Dev-C++] new is a wrapper around malloc so... >Date: Wed, 16 Jul 2003 00:40:19 +0530 > > > > In 16 bit your code is separated into 'segments' each a maximum of 64k >in > > size. 32-bit can have up to 2GB segments (!!!). > >4G, right? (2^32). > >However, that's true only on a 32-bit system (as you've said)... what >platform are you building on? On 16-bit (`real-mode') DOS, even though >sizeof(farptr) will give you four, it cannot address 32-bits worth of >memory. Far pointers work like this: > > 32 bits of farptr = > 16 bits of segment . > 16 bits of offset > >The effective address is actually calculated by multiplying the segment by >16 decimal (0x10 (which is equivalent to left-shifting by four)) and then >ADDING the offset... so that if your far-ptr has this value: > > 0x1234abcd > >Written as: > > 1234:abcd > >Its effective address, which is worth 20-bits (and can therefore address >2^20 = 1M) is calculated as: > > 0x12340 >+ 0xabcd >------------- >= 0x1cf0d > >Whereas, in the flat memory model(protected-mode), the effective address >would itself be > > 0x1234abcd > >-- >Abhijit Shylanath >Homepage: http://mudeth.tripod.com/ > _________________________________________________________________ On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile |
|
From: Per W. <pw...@ia...> - 2003-07-16 10:27:21
|
A 32-bit pionter is an unsigned entity, so it can span 2^32 bytes - 4GB. From this address space, the different OS then reserves areas for OS code, buffers, IPC etc. Depending on OS, you may normally not allocate more than 2 or 3GB for a single application. This is the big reason why the world is so desperately wanting 64-bit machines. In database solutions it is quite common to memory-map the database files. However, 2-3GB is a puny database. /Per W On Wed, 16 Jul 2003, Daniel Glenfield wrote: > All I know is that the MSDN documentation I read says 2GB. I'm not sure > about how you calculate it all, so you're one up on me! > > > >From: "Abhijit Shylanath" <mu...@gm...> > >To: "Daniel Glenfield" <sp...@ho...> > >CC: "Dev-Cpp mailing list" <dev...@li...> > >Subject: RE: [Dev-C++] new is a wrapper around malloc so... > >Date: Wed, 16 Jul 2003 00:40:19 +0530 > > > > > > > In 16 bit your code is separated into 'segments' each a maximum of 64k > >in > > > size. 32-bit can have up to 2GB segments (!!!). > > > >4G, right? (2^32). > > > >However, that's true only on a 32-bit system (as you've said)... what > >platform are you building on? On 16-bit (`real-mode') DOS, even though > >sizeof(farptr) will give you four, it cannot address 32-bits worth of > >memory. Far pointers work like this: > > > > 32 bits of farptr = > > 16 bits of segment . > > 16 bits of offset > > > >The effective address is actually calculated by multiplying the segment by > >16 decimal (0x10 (which is equivalent to left-shifting by four)) and then > >ADDING the offset... so that if your far-ptr has this value: > > > > 0x1234abcd > > > >Written as: > > > > 1234:abcd > > > >Its effective address, which is worth 20-bits (and can therefore address > >2^20 = 1M) is calculated as: > > > > 0x12340 > >+ 0xabcd > >------------- > >= 0x1cf0d > > > >Whereas, in the flat memory model(protected-mode), the effective address > >would itself be > > > > 0x1234abcd > > > >-- > >Abhijit Shylanath > >Homepage: http://mudeth.tripod.com/ > > > > _________________________________________________________________ > On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Daniel G. <sp...@ho...> - 2003-07-16 11:58:56
|
Ahhhhhhhhhhh, so that's why everyone wants 64-bits. Games too are requiring more, probably because of the same memory-mapping issues. >From: Per Westermark <pw...@ia...> >To: Daniel Glenfield <sp...@ho...> >CC: mu...@gm..., <dev...@li...> >Subject: RE: [Dev-C++] new is a wrapper around malloc so... >Date: Wed, 16 Jul 2003 12:26:07 +0200 (CEST) > >A 32-bit pionter is an unsigned entity, so it can span 2^32 bytes - 4GB. >From this address space, the different OS then reserves areas for OS code, >buffers, IPC etc. Depending on OS, you may normally not allocate more than >2 or 3GB for a single application. > >This is the big reason why the world is so desperately wanting 64-bit >machines. In database solutions it is quite common to memory-map the >database files. However, 2-3GB is a puny database. > >/Per W > >On Wed, 16 Jul 2003, Daniel Glenfield wrote: > > > All I know is that the MSDN documentation I read says 2GB. I'm not sure > > about how you calculate it all, so you're one up on me! > > > > > > >From: "Abhijit Shylanath" <mu...@gm...> > > >To: "Daniel Glenfield" <sp...@ho...> > > >CC: "Dev-Cpp mailing list" <dev...@li...> > > >Subject: RE: [Dev-C++] new is a wrapper around malloc so... > > >Date: Wed, 16 Jul 2003 00:40:19 +0530 > > > > > > > > > > In 16 bit your code is separated into 'segments' each a maximum of >64k > > >in > > > > size. 32-bit can have up to 2GB segments (!!!). > > > > > >4G, right? (2^32). > > > > > >However, that's true only on a 32-bit system (as you've said)... what > > >platform are you building on? On 16-bit (`real-mode') DOS, even though > > >sizeof(farptr) will give you four, it cannot address 32-bits worth of > > >memory. Far pointers work like this: > > > > > > 32 bits of farptr = > > > 16 bits of segment . > > > 16 bits of offset > > > > > >The effective address is actually calculated by multiplying the segment >by > > >16 decimal (0x10 (which is equivalent to left-shifting by four)) and >then > > >ADDING the offset... so that if your far-ptr has this value: > > > > > > 0x1234abcd > > > > > >Written as: > > > > > > 1234:abcd > > > > > >Its effective address, which is worth 20-bits (and can therefore >address > > >2^20 = 1M) is calculated as: > > > > > > 0x12340 > > >+ 0xabcd > > >------------- > > >= 0x1cf0d > > > > > >Whereas, in the flat memory model(protected-mode), the effective >address > > >would itself be > > > > > > 0x1234abcd > > > > > >-- > > >Abhijit Shylanath > > >Homepage: http://mudeth.tripod.com/ > > > > > > > _________________________________________________________________ > > On the move? Get Hotmail on your mobile phone >http://www.msn.co.uk/msnmobile > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: VM Ware > > With VMware you can run multiple operating systems on a single machine. > > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > >------------------------------------------------------- >This SF.net email is sponsored by: VM Ware >With VMware you can run multiple operating systems on a single machine. >WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the >same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger |
|
From: Per W. <pw...@ia...> - 2003-07-16 12:17:20
|
64-bit isn't just a speed issue :-) Anyway, while most motherboards may only support 2-4GB memory, but the 386 processor isn't limited to 4GB physical memory, and some server motherboards supports a lot more. However, with 32-bit paged memory the machine may then run a number of applications each allocating 2-3GB. But each individual application is limited. There is a way around it. It's the dreaded 48-bit far pointer (16:32) where the processor is supporting up to 65536 memory segments of up to 4GB each. However, all programmers and compiler vendors have already learned to hate the old 16:16 far pointers from 8086 (1MB) and 80286 (16MB) so nobody is rushing for 48-bit pointers. Segmented memory doesn't support or work very well with a number of concepts we have learned to use and love with our current paged memory model: - On-demand allocation. Automatically grow the stack in 4kB increments whenever needed. - Memory fragmentation. In a paged environment, the OS may never get fragmented memory, since each memory page is identical. It just keeps track of a list of available pages, and maps in the first available page when a process needs more memory. With segmented memory, the OS will normally have to block the task and move the memory segments around in the physical memory to get a continuous free block large enough for a memory allocation. /Per W On Wed, 16 Jul 2003, Daniel Glenfield wrote: > Ahhhhhhhhhhh, so that's why everyone wants 64-bits. Games too are requiring > more, probably because of the same memory-mapping issues. > > > >From: Per Westermark <pw...@ia...> > >To: Daniel Glenfield <sp...@ho...> > >CC: mu...@gm..., <dev...@li...> > >Subject: RE: [Dev-C++] new is a wrapper around malloc so... > >Date: Wed, 16 Jul 2003 12:26:07 +0200 (CEST) > > > >A 32-bit pionter is an unsigned entity, so it can span 2^32 bytes - 4GB. > >From this address space, the different OS then reserves areas for OS code, > >buffers, IPC etc. Depending on OS, you may normally not allocate more than > >2 or 3GB for a single application. > > > >This is the big reason why the world is so desperately wanting 64-bit > >machines. In database solutions it is quite common to memory-map the > >database files. However, 2-3GB is a puny database. > > > >/Per W > > > >On Wed, 16 Jul 2003, Daniel Glenfield wrote: > > > > > All I know is that the MSDN documentation I read says 2GB. I'm not sure > > > about how you calculate it all, so you're one up on me! > > > > > > > > > >From: "Abhijit Shylanath" <mu...@gm...> > > > >To: "Daniel Glenfield" <sp...@ho...> > > > >CC: "Dev-Cpp mailing list" <dev...@li...> > > > >Subject: RE: [Dev-C++] new is a wrapper around malloc so... > > > >Date: Wed, 16 Jul 2003 00:40:19 +0530 > > > > > > > > > > > > > In 16 bit your code is separated into 'segments' each a maximum of > >64k > > > >in > > > > > size. 32-bit can have up to 2GB segments (!!!). > > > > > > > >4G, right? (2^32). > > > > > > > >However, that's true only on a 32-bit system (as you've said)... what > > > >platform are you building on? On 16-bit (`real-mode') DOS, even though > > > >sizeof(farptr) will give you four, it cannot address 32-bits worth of > > > >memory. Far pointers work like this: > > > > > > > > 32 bits of farptr = > > > > 16 bits of segment . > > > > 16 bits of offset > > > > > > > >The effective address is actually calculated by multiplying the segment > >by > > > >16 decimal (0x10 (which is equivalent to left-shifting by four)) and > >then > > > >ADDING the offset... so that if your far-ptr has this value: > > > > > > > > 0x1234abcd > > > > > > > >Written as: > > > > > > > > 1234:abcd > > > > > > > >Its effective address, which is worth 20-bits (and can therefore > >address > > > >2^20 = 1M) is calculated as: > > > > > > > > 0x12340 > > > >+ 0xabcd > > > >------------- > > > >= 0x1cf0d > > > > > > > >Whereas, in the flat memory model(protected-mode), the effective > >address > > > >would itself be > > > > > > > > 0x1234abcd > > > > > > > >-- > > > >Abhijit Shylanath > > > >Homepage: http://mudeth.tripod.com/ > > > > > > > > > > _________________________________________________________________ > > > On the move? Get Hotmail on your mobile phone > >http://www.msn.co.uk/msnmobile > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.net email is sponsored by: VM Ware > > > With VMware you can run multiple operating systems on a single machine. > > > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > > > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > > >------------------------------------------------------- > >This SF.net email is sponsored by: VM Ware > >With VMware you can run multiple operating systems on a single machine. > >WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > >same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > >_______________________________________________ > >Dev-cpp-users mailing list > >Dev...@li... > >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > _________________________________________________________________ > It's fast, it's easy and it's free. Get MSN Messenger today! > http://www.msn.co.uk/messenger > > |
|
From: Abhijit S. <mu...@gm...> - 2003-07-15 19:05:11
|
> In 16 bit your code is separated into 'segments' each a maximum of 64k in > size. 32-bit can have up to 2GB segments (!!!). 4G, right? (2^32). However, that's true only on a 32-bit system (as you've said)... what platform are you building on? On 16-bit (`real-mode') DOS, even though sizeof(farptr) will give you four, it cannot address 32-bits worth of memory. Far pointers work like this: 32 bits of farptr = 16 bits of segment . 16 bits of offset The effective address is actually calculated by multiplying the segment by 16 decimal (0x10 (which is equivalent to left-shifting by four)) and then ADDING the offset... so that if your far-ptr has this value: 0x1234abcd Written as: 1234:abcd Its effective address, which is worth 20-bits (and can therefore address 2^20 = 1M) is calculated as: 0x12340 + 0xabcd ------------- = 0x1cf0d Whereas, in the flat memory model(protected-mode), the effective address would itself be 0x1234abcd -- Abhijit Shylanath Homepage: http://mudeth.tripod.com/ |