VOGONS


First post, by tigrou

User metadata
Rank Newbie
Rank
Newbie

I have wrote the following C code under Turbo C 3.0:

#include <stdio.h>
#include <alloc.h>

void main()
{
int i;
for (i = 1 ; i < 20 ; i++)
{
unsigned char *p = (unsigned char *)malloc(10000);
if(!p) printf("FAIL %d", i);
}
}

It allocate a block of 10.000 bytes, 20 times.
What I don't understand is why it fails after 6 iterations (when about 60000 bytes have been allocated)
It seems it can't allocate more than 64K in total. I understand that code is running in 16-bit mode so there is limitations but it should work (I should at least be able to allocate about 640K).

What I have tried that does not work :
- change memory model to "compact", "large", "huge"
- add "far" keyword in pointer definition.
- use "farmalloc" instead of "malloc"

Last edited by tigrou on 2020-04-01, 14:36. Edited 1 time in total.

Reply 1 of 12, by BloodyCactus

User metadata
Rank Oldbie
Rank
Oldbie

farmalloc should work.

https://www.drdobbs.com/using-large-arrays-in … 84402289?pgno=1

under dos, if you want large chunks reliably, use dos int21h function 48h and cast it as a far pointer with MKFP. just be aware of starving other functions that might allocate memory punching SBRK if you go and allocate it all.

--/\-[ Stu : Bloody Cactus :: [ https://bloodycactus.com :: http://kråketær.com ]-/\--

Reply 3 of 12, by Ringding

User metadata
Rank Member
Rank
Member

There should be a menu item "Get Info" – in Turbo C 2 it’s in the Compile menu – that shows the amount of available memory. For me it shows 295K (under qemu). This would be roughly the amount of memory you can expect to be able to allocate from your program.

Reply 5 of 12, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie
Errius wrote on 2020-04-02, 00:57:

Doesn't C make you declare all variables at the beginning of the function? I think declaring on first use was introduced with C++.

Not at the beginning of a function, but before any non-declarations in the current scope. *p is declared at the beginning of new scope (inside {}) so it's fine.

Reply 9 of 12, by Errius

User metadata
Rank l33t
Rank
l33t

The version history of the Borland compilers is so confusing that a few years ago I made this list for my own reference:

  • TURBO C
    • Borland Turbo C 1.0
      • 1987: DOS
    • Borland Turbo C 1.5
      • 1988: DOS
    • Borland Turbo C 2.0
      • 1988: DOS
    • Borland Turbo C 2.0 1
      • 1989: DOS
  • TURBO C++
    • Borland Turbo C++ 1.0
      • 1990: DOS
    • Borland Turbo C++ 1.01
      • 1991: DOS
    • Borland Turbo C++ 3.0
      • 1992: DOS, Windows
    • Borland Turbo C++ 3.1
      • 1992: Windows
    • Borland Turbo C++ 4.5
      • 1995: Windows
  • C++
    • Borland C++ 1.0
      • 1992: OS/2
    • Borland C++ 1.5
      • 1992: OS/2
    • Borland C++ 2.0
      • 1991: DOS
      • 1993: OS/2
    • Borland C++ 3.0
      • 1991: DOS, Windows
    • Borland C++ 3.1
      • 1992: DOS, Windows
    • Borland C++ 4.0
      • 1993: Windows
    • Borland C++ 4.01
      • 1993: Windows
    • Borland C++ 4.02
      • 1994: Windows
    • Borland C++ 4.5
      • 1994: Windows
    • Borland C++ 4.51
      • 1995: Windows
    • Borland C++ 4.52
      • 1995: Windows
    • Borland C++ 4.53
      • 1995: Windows
    • Borland C++ 5.0
      • 1996: Windows
    • Borland C++ 5.01
      • 1996: Windows
    • Borland C++ 5.02
      • 1997: Windows
    • Borland C++ 5.5
      • 2000: Windows. Command-line compiler only (no IDE)
  • C++BUILDER
    • Borland C++Builder 1.0
      • 1997: Windows
    • Borland C++Builder 3.0
      • 1998: Windows
    • Inprise Borland C++Builder 4.0
      • 1999: Windows
    • Inprise Borland C++Builder 5.0
      • 2000: Windows
    • Borland C++Builder 6.0
      • 2002: Windows
    • Borland C++BuilderX 1.0
      • 2003: Windows
    • Borland C++Builder 2006 (10.0)
      • 2005: Windows
    • CodeGear C++Builder 2007 (11.0)
      • 2007: Windows
    • Embarcadero C++Builder 2009 (12.0)
      • 2008: Windows
    • Embarcadero C++Builder 2010 (14.0)
      • 2009: Windows
    • Embarcadero C++Builder XE (15.0)
      • 2010: Windows
    • Embarcadero C++Builder XE2 (16.0)
      • 2011: Windows
    • Embarcadero C++Builder XE3 (17.0)
      • 2012: Windows
    • Embarcadero C++Builder XE4 (18.0)
      • 2013: Windows
    • Embarcadero C++Builder XE5 (19.0)
      • 2013: Windows
    • Embarcadero C++Builder XE6 (20.0)
      • 2014: Windows
    • Embarcadero C++Builder XE7 (21.0)
      • 2014: Windows
    • Embarcadero C++Builder XE8 (22.0)
      • 2015: Windows
    • Embarcadero C++Builder 10 Seattle (23.0)
      • 2015: Windows
    • Embarcadero C++Builder 10.1 Berlin (24.0)
      • 2016: Windows
    • Embarcadero C++Builder 10.2 Tokyo (25.0)
      • 2017: Windows
    • Embarcadero C++Builder 10.3 Rio (26.0)
      • 2018: Windows
    • Embarcadero C++Builder 10.4 Sydney (27.0)
      • 2020: Windows
    • Embarcadero C++Builder 11 Alexandria (28.0)
      • 2021: Windows
    • Embarcadero C++Builder 12 Athens (29.0)
      • 2023: Windows

(Corrections & additions are welcome)

Last edited by Errius on 2023-12-16, 23:54. Edited 10 times in total.

Is this too much voodoo?

Reply 12 of 12, by Errius

User metadata
Rank l33t
Rank
l33t

No, I actually bought Turbo C++ 3.1 back when it was new and was extremely bummed to find it was Windows only. Not just the IDE - it wouldn't compile DOS programs at all.

Is this too much voodoo?