Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. Help needed in Memory Management in C++

Help needed in Memory Management in C++

Scheduled Pinned Locked Moved IT & Infrastructure
helpc++performance
10 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msramachandran
    wrote on last edited by
    #1

    I encountered a problem in c++ while allocating memory more than 64KB in DOS throughTurbo C++ compiler. For some program in needed 1MB of memory. There wasn't any error for not much memory but still i could get a maximum of 60KB. Can anybody help in the problem

    ramachandran m s

    Z J 2 Replies Last reply
    0
    • M msramachandran

      I encountered a problem in c++ while allocating memory more than 64KB in DOS throughTurbo C++ compiler. For some program in needed 1MB of memory. There wasn't any error for not much memory but still i could get a maximum of 60KB. Can anybody help in the problem

      ramachandran m s

      Z Offline
      Z Offline
      ZoogieZork
      wrote on last edited by
      #2

      For a 16-bit program, the largest block of memory you can allocate is 65536 bytes (minus 16 bytes, if I remember correctly, since it may not return a pointer on a page boundary). You'll need to either allocate a number of blocks less than 64KB and index through them, or use a compiler capable of producing 32-bit executables (is there a specific reason you're using Turbo C++ for DOS?) - Mike

      M 1 Reply Last reply
      0
      • Z ZoogieZork

        For a 16-bit program, the largest block of memory you can allocate is 65536 bytes (minus 16 bytes, if I remember correctly, since it may not return a pointer on a page boundary). You'll need to either allocate a number of blocks less than 64KB and index through them, or use a compiler capable of producing 32-bit executables (is there a specific reason you're using Turbo C++ for DOS?) - Mike

        M Offline
        M Offline
        msramachandran
        wrote on last edited by
        #3

        :rose::-O

        Thanks for ur information mike. is there any 32 bit compilers in dos. the specific reason i am using turbo c++ is i want to get rid of that windows dlls. i want my program to run seperately without any external support. if there any possibilities plz return back to me.

        ramachandran m s

        Z 1 Reply Last reply
        0
        • M msramachandran

          :rose::-O

          Thanks for ur information mike. is there any 32 bit compilers in dos. the specific reason i am using turbo c++ is i want to get rid of that windows dlls. i want my program to run seperately without any external support. if there any possibilities plz return back to me.

          ramachandran m s

          Z Offline
          Z Offline
          ZoogieZork
          wrote on last edited by
          #4

          Try DJGPP: http://www.delorie.com/djgpp/[^] - Mike

          M 1 Reply Last reply
          0
          • Z ZoogieZork

            Try DJGPP: http://www.delorie.com/djgpp/[^] - Mike

            M Offline
            M Offline
            msramachandran
            wrote on last edited by
            #5

            i feel its a little bit bitter to work in a command line compiler. is there any other compilers like tc which has inbuilt editor & debugging facilities & that works well in DOS

            ramachandran m s

            1 Reply Last reply
            0
            • M msramachandran

              I encountered a problem in c++ while allocating memory more than 64KB in DOS throughTurbo C++ compiler. For some program in needed 1MB of memory. There wasn't any error for not much memory but still i could get a maximum of 60KB. Can anybody help in the problem

              ramachandran m s

              J Offline
              J Offline
              Jijo Raj
              wrote on last edited by
              #6

              In the TC IDE, take Options->Compiler-> Code Generation and in the "Model" group, change selection to "Huge". Now you can allocate memory more than 64Kb. :) Isn't it simple ? ;) Regards, Jijo ________________________________ Yesterday is history, Tomorrow is a mystery, But today is a present.

              M 1 Reply Last reply
              0
              • J Jijo Raj

                In the TC IDE, take Options->Compiler-> Code Generation and in the "Model" group, change selection to "Huge". Now you can allocate memory more than 64Kb. :) Isn't it simple ? ;) Regards, Jijo ________________________________ Yesterday is history, Tomorrow is a mystery, But today is a present.

                M Offline
                M Offline
                msramachandran
                wrote on last edited by
                #7

                :rose:tks for the immediate responce. :confused: i've tried this earlier. but since if i request for more than 64KB through malloc() it is allocating a maximum of 63KB. is there any solution for this problem or any other function or lib can solve this problem. :-O plz respond to me if there any.

                ramachandran m s

                J 1 Reply Last reply
                0
                • M msramachandran

                  :rose:tks for the immediate responce. :confused: i've tried this earlier. but since if i request for more than 64KB through malloc() it is allocating a maximum of 63KB. is there any solution for this problem or any other function or lib can solve this problem. :-O plz respond to me if there any.

                  ramachandran m s

                  J Offline
                  J Offline
                  Jijo Raj
                  wrote on last edited by
                  #8

                  Dear ramachandran, The problem is simple. Please use farmalloc () function in the alloc.h. This function can allocate memory more than 64KB. Then the only condition for the function is that the model should be greater than tiny. I hope this will solve your problem. Simple, isn't it ? ;) Regards, Jijo. ________________________________ Yesterday is history, Tomorrow is a mystery, But today is a present.

                  M 1 Reply Last reply
                  0
                  • J Jijo Raj

                    Dear ramachandran, The problem is simple. Please use farmalloc () function in the alloc.h. This function can allocate memory more than 64KB. Then the only condition for the function is that the model should be greater than tiny. I hope this will solve your problem. Simple, isn't it ? ;) Regards, Jijo. ________________________________ Yesterday is history, Tomorrow is a mystery, But today is a present.

                    M Offline
                    M Offline
                    msramachandran
                    wrote on last edited by
                    #9

                    :rose:Tks Jijo, i think this will solve my problem. but i can't understand the systax of this function. i am getting some error message or the system hangs while using this function. can u send me any example programs demonstrating this.

                    :-O kind regards from, ramachandran m s

                    J 1 Reply Last reply
                    0
                    • M msramachandran

                      :rose:Tks Jijo, i think this will solve my problem. but i can't understand the systax of this function. i am getting some error message or the system hangs while using this function. can u send me any example programs demonstrating this.

                      :-O kind regards from, ramachandran m s

                      J Offline
                      J Offline
                      Jijo Raj
                      wrote on last edited by
                      #10

                      first include the header file alloc.h

                          #include alloc.h
                      

                      Eg: if you want to allocate a char array using farmalloc (),

                          char far* ptr;
                          ptr = (char far*) farmalloc ( size );
                      

                      now do the required operations. The only difference is that we used a far pointer it behaves just like an ordinary pointer but, ordinary pointers like char* can only handle 64KB of memory locations, but this far pointer can handle memory of more than 64KB. Take care to free the allocated memory using farfree().

                          farfree ( ptr );
                      

                      hope now all the problem solves. If you face anymore, please feel free to ask me. ;) Regards, Jijo. ;) ________________________________ Yesterday is history, Tomorrow is a mystery, But today is a present.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups