Thread: Memory problem with Borland C 3.1

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    8

    Memory problem with Borland C 3.1

    Hi….
    Sorry for my English and for my question but I’ve very big problem!!

    This is my first question in this forum, but I’ve a very big problem. I’m writing a code for Borland C 3.1 that has a function with the following prototype:

    Code:
    Void Retrun_string (int byte1, int byte2, char *ptr)
    The function take in input the 2 byte and wrote, in output, to a char pointed by ptr pointer a string:

    Code:
    Char *other_string[25];

    My problem is that in this fuction there are lots of string allocation (more than 64K), all string vector are of the type:


    Code:
    const char *string[] = {
    		“string1”,
    		“string2”,
    		……
    		“stringN”,
    }

    I’ve lots of this vector because I need to make lots of correspondence between the two bytes and the string. And I use this way for making an easier:

    Code:
    Strcpy (ptr, string[n]);
    The problem is that I must work in a windows 98 space with a Borland c 3.1 (1991). I found on the web that with this kind of workspace there is lots of memory problem because this compiler (that works in MSdos emulation on win98) doesn’t allowed more than 64k of memory. When I run my program I’ve a runtime error in the memory that every times changed and is not periodic but very random. Sometimes my program run without problems, some times all the system crashed, like a MATRIX screensaver. I note that I wrote (random) in lots of parts of memory system for example so0metimes “I” wrote in the keyboard memory, or in the video memory or in the system memory. If I’m lucky the system tell me that I’m trying to access to a reserve and critical part of the memory.

    I can’t use an extern file for downloading on runtime the needed string. If I run the program with out my fuction (all the fuction commented) I’ve not problems, nothing. If I run with the entire string vector commented I’ve not running problem. I think the problem are the strings!

    When I run my executable file on a winxp workstation I’ve fewer problems… but I must work on 98 systems…. I tried to working with out a pointer in my fuction, but I’ve the same problems. I tried changing with this other fuction:


    Code:
    Static char string2[25];
    Retrun_string (int byte1, int byte2)
    {
    	….
    	Strcpy (string2, string[n]);
    }
    I found on te web lots of people with memory troubles in Borland C, very similar to mine. Lots of people migrate to Borland 5 or made a file where put all the string, but I can’t!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You should be able to use more than 64K of memory by using "large memory model" and "far" pointers.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    I don't find the option "far" pointers.. i've only found far data, are the sames?

    In more i've found that i've the 80286 instruction set....
    I can at the maximum setting 80386 instruction set.. but i've a pentium architecture.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    far is an extra keyword in 16-bit x86 compilers, which tells the compiler that this pointer constists of two 16 bit values:
    - an offset
    - a segment
    Together these can address any address 0..1MB [exactly 0..1MB+64K-16 - but for most purposes, you can ignore that last bit, as there is a huge hole at 640K..1MB in DOS].

    In "large" mode, all pointers are "far".

    http://en.wikipedia.org/wiki/C_memory_model

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    Unfortunally i'm already in large mode...

    I've checked my make file.. and i've the tag specifier in the option

    -ml

    If i'm in large mode, now i've also far pointers.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So you should be able to use large chunks of memory (bigger than 64K).

    You are not, by any chance, creating these string variables on the stack, are you? That wouldn't work, I think. Or perhaps you can if you use "huge" memory model - I can't quite remember all the details.

    Actually, searching for "borland C huge" turns up this:
    http://www.binarica.com/data/about/bc201.html

    If that's not helping, please provide more info:
    What exactly is the error message(s) that you get?



    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    I don't get message error.. during runtime my system crashed.. only sometimes i get a message error from windows 98: access memory falied.

    I think all variables are created when i run the program in the stack. maybe i've not understand your question..

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Is there ANY reason you can't actually port this to a 32-bit Windows Console application?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    As yet, you've yet to post any code which seems capable of being compiled, let alone being run.

    Also, there seems to be at least one place where you messed up on the parameter type, based on the parameter being passed, and another place of not pointing to allocated memory.

    Post some actual code which demonstrates the problem (as best you can anyway).

    Even in the large memory models, the size of any single object is still limited to 64K, so if you have many thousands of strings in your array, that might be a problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    i've something around 2000 string of ~20 byte.

    40K byte sigh

    In more i've the other parts of the program running and the compiler...

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Still, if this is for Win98 or newer systems, you do not need to use Borland C - plenty of freely available 32-bit compilers to solve the problem, and then your 64K limit becomes 2GB limit, which is much less of a hindrance.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    I tryed to migreta my software to a "modern" borland C that hasn't this kind of problem, like borland C++ 5, that works on windows space.. but i've a problem conversion with a fuction on my code.

    This is not a my code, but a old source created for borland c++, and exatly i've a traslation problem between Borland 3.1 to Borland 5.1 in an interrupt fuction, i try telling you if you can helping me to translate this fuction to new borland standard i think i could resolving my problem:

    void Inizializza_Linea_L_(void interrupt (*proc)());
    void Inizializza_Linea_K_(void interrupt (*proc)());

    I think the compiuler doesn't accept this kind of fuction protoip and this is the main fuction of all the source, but is a low level fuction.. and i think could be very dangerous to modify this fuction, bouce in the end my .exe run in a particolar space, in an other .exe program, with a particolar socket that, unfortunally, i don't know. But if is easy to modify this code, i can try to modify.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    What sort of things do those "interrupt" functions do in the old version of the program?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Nov 2007
    Posts
    8
    Is an interrutp from a serial or USB (depends) device with an apposit firmware inside, that i can't modify or see the code. That's is why i don't wan to modify a lot the structure of my program.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    In Win32, you no longer have to worry about the low-level detail of handling each byte being transferred to/from some piece of hardware.

    For instance, to access a COM port, you would begin with CreateFile and a filename like "\\\\.\\COM3"
    Then scroll down to Communications Resources and carry on reading and following links.

    > That's is why i don't wan to modify a lot the structure of my program.
    To be honest, I might think about starting again.
    If you're working with some old software, which has a history of being modified by many different people over a number of years, then it's going to look pretty horrible in places. It will contain all sorts of 'DOS-hacks' necessary to make it work on DOS (eg. interrupts, worrying about 64K limits etc), and may even contain large amounts of dead code. It may also implement some features which are no longer needed.

    Attempting a line-by-line translation of that to Win32 will retain much of that, and add another layer of confusion for future maintainers.

    But if you do rewrite it in Win32 from scratch, then it will be a nice clean implementation which would be a solid base for future development and enhancement. You keep the old program as it stands as a reference to work to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with atl memory cleaning
    By Mariam1989 in forum Windows Programming
    Replies: 1
    Last Post: 11-11-2008, 12:35 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Memory problem...?
    By Xzyx987X in forum Windows Programming
    Replies: 4
    Last Post: 06-30-2004, 05:02 PM
  4. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM
  5. Program abort due to memory problem
    By cazil in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2002, 12:55 PM