CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Join Date
    Feb 2004
    Posts
    7

    Exclamation near or far allocation

    hi all

    i have small question but i think its too important

    dose new and delete allocate in hear heap or far heap
    if in near heap how i can allocate in the far heap

    thanks for all
    [SIZE=1]

  2. #2
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222

    Smile

    i have small question but i think its too important
    Too important or too un-important?

  3. #3
    Join Date
    Feb 2004
    Posts
    138

    Re: near or far allocation

    Originally posted by ce_yas
    hi all

    i have small question but i think its too important

    dose new and delete allocate in hear heap or far heap
    if in near heap how i can allocate in the far heap

    thanks for all
    [SIZE=1]
    What do you mean by far and near ?
    Sometimes there are things that are very near but they are still unreacheable.
    Is that near/far you are talking about ?

  4. #4
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588
    "Near" and "Far" are legacies of 16 bit programs. So if you develop 32-bit programs, there is no such distinction anymore. For 16-bit programming, it depends on your compiler settings and runtime environment.
    Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
    Supports C++ and VB out of the box, but can be configured for other languages.

  5. #5
    Join Date
    Feb 2004
    Posts
    138

    Yves, Monsieur

    Originally posted by Yves M
    "Near" and "Far" are legacies of 16 bit programs. So if you develop 32-bit programs, there is no such distinction anymore. For 16-bit programming, it depends on your compiler settings and runtime environment.
    What is far and what is near ?

    Thanks Monsieur alot

  6. #6
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    If you step into the way back machine we can visit a place called 8 bit or 16bit programming. In 16 bit programming a program could only address 64k of memory. because each byte of memory addressed must be able to be represented as a value in a 16bit variable... Get it? 2xx8 = 256 unique values
    2xx16 = 256x256 = 65536 bits

    65536 bits => 65536/1024 => 64k... get it?


    Now crafty programmers back in the day came up with something called segments to get around this huge limitation for doing anythign but trivial programming. Segments were used for breaking up data and getting around the 64k barrior. We hada code segment, data segment, static segment yada yada yada... We tied them all together with memory models... tiny, small, medium, large and HUGE.

    I know I know we still have segments today.. but they're different back then they were more important because if you were unaware of them you'd bash your head pretty quickly.

    OK each segment was 64 k large right... so if you wanted to acess something in your data segment for example you could do so with a near pointer cause all the near pointers were addressed to work in that segment. Now if you ran out of space in your data segment no problem you could tinker with compiler settings(memory models) and whalla... add another data segment. Only if you added another data segment you couldn't acess it with a near pointer... no no.. it was not long enough to address outside of it's Data Seg. So you would use a FAR pointer right!!... Only that's not the half of it.. you see in small memory model all the pointers defaulted to near pointers, in large memory models all the pointers defaulted to far pointers and in medium you could have either... Confusing... Don't even get me started on DLL's...

    DS not equal to SS.... DS not equal to SS.... my eye still twitches when I say that....

    Complicated you say? Yes it was a little complicated. It could get very complicated. That's why early programmers typically hated DOS and 16 bit windows programs for large applications. That's why intel and it's accursed segmented memory structure was cursed through out the land by programmers with nervous twitches and shaky hands. And why Motorola (apple's and NEXT's) and it's flat memory structure was really loved and ultimately addopted by Intel.

    Anyway. Segments are still with us today. Only today with 32 bit pointers they can access like 2 gig of memory. Also things like stack and heap grow and shrink dynamically as your program needs them. Back in the day we had to statically allocate segments and statically allocate how much of the segment we would use for things like the stack and the heap. Oh what a joy it was to try to calculate the stack size needed for a recursive algorithm.... Lick your finger put it in the wind and hope nothing blows up....

    Anyway... let's leave the way back machine and thank God we live in a more enlightened time.
    Last edited by JMS; February 17th, 2004 at 01:22 PM.

  7. #7
    Join Date
    Feb 2004
    Posts
    138
    Thanks, I got it..

  8. #8
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by JMS
    If you step into the way back machine we can visit a place called 8 bit or 16bit programming. In 16 bit programming a program could only address 64k of memory.
    That depends on what processor. The original IBM PC uses a 8088 processor, which is 16-bit and capable of accessing 1 MB of memory.
    Originally posted by JMS
    Now crafty programmers back in the day came up with something called segments to get around this huge limitation for doing anythign but trivial programming.
    It was not the programmers; it was the processor manufacturer that designed the processor to use segments. For example, Intel designed the 8086 and 8088 with the following:
    • Segment (ds, ss, es and others) and offset (sp, ax and others) registers
    • machine instructions that could specify one of the segment registers for accessing memory in various segments
    • machine instructons that could use either near or far addresses

    Originally posted by JMS
    I know I know we still have segments today
    Not in a pentium processor using 32-bit addressing mode, as does 32-bit Windows does.
    Originally posted by JMS
    Now if you ran out of space in your data segment no problem you could tinker with compiler settings(memory models) and whalla... add another data segment.
    There are many other ways to access more data and such. It is possible to allocate memory during execution and address it in a variety of ways, including use of far pointers. However simply by loading a segment register, it is possible to access up to 64k of the memory using a near pointer.
    Originally posted by JMS
    Only if you added another data segment you couldn't acess it with a near pointer
    Speak for yourself; I could.
    Originally posted by JMS
    So you would use a FAR pointer right!!... Only that's not the half of it.. you see in small memory model all the pointers defaulted to near pointers, in large memory models all the pointers defaulted to far pointers and in medium you could have either...
    Actually the memory model determines the default addressing for the data and for instructions separately so the medium and compact memory models used combinations of addressing differnt from small and large.
    Originally posted by JMS
    Complicated you say? Yes it was a little complicated. It could get very complicated. That's why early programmers typically hated DOS and 16 bit windows programs for large applications. That's why intel and it's accursed segmented memory structure was cursed through out the land by programmers with nervous twitches and shaky hands. And why Motorola (apple's and NEXT's) and it's flat memory structure was really loved and ultimately addopted by Intel.
    The flat memory model was not invented by Motorola.
    Originally posted by JMS
    Back in the day we had to statically allocate segments and statically allocate how much of the segment we would use for things like the stack and the heap.
    All of that could be changed dynamically during execution by assembler programs.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #9
    Join Date
    Feb 2004
    Posts
    7
    Thanks for all especially for JMS. i have some information about what you say but i was confused and now i can go on.

  10. #10
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    The segment registers are still there and accessible in 32-bit mode. But they now have access right meanings, that's why you have to set up segment descriptors directly after switching to protected mode.
    All the buzzt
    CornedBee

  11. #11
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by ce_yas
    Thanks for all especially for JMS. i have some information about what you say but i was confused and now i can go on.
    You can't rely on anything JMS said since there are so many innacuracies in it. It is amazing to me that you are using that instead of finding something that is accurate. There is an abundance of material that can be found; I did not say much more because there is so much available.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  12. #12
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by CornedBee
    The segment registers are still there and accessible in 32-bit mode. But they now have access right meanings, that's why you have to set up segment descriptors directly after switching to protected mode.
    Is it possible to use a segment register as part of an address while in protected (32-bit) mode? Is it possible to use a far address (segment:offset) or a near address (offset) in a machine instruction while in protected (32-bit) mode?

    Maybe I will look for relevant Intel documentation later.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  13. #13
    Join Date
    Feb 2004
    Posts
    7
    Thanks Sam i hope if you can give me any other information about this issue, until now i didn't have any error in my application but in the past i have a problem in some of my application in memory allocation so i hope if you can give me any information may help me.

  14. #14
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    If you are writing a 32-bit Windows program then you don't need to know anything about near and far except that they are ignored. That is why there are so few relevant answers; the real answer is that there is nothing more to be said that is relevant.

    If you can remember more details about the problems in the past then you could ask about that but otherwise I think it is better to just move forward and wait until you encounter a problem in the future.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  15. #15
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Sam: I think only in kernel mode.
    All the buzzt
    CornedBee

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured