| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | ANSI C vs. API calls |
WvO> There are several API calls available that seem to do
WvO> the same thing as standard ANSI C functions, like
WvO> open() vs. DosOpen(), mkdir() vs. DosCreateDir() and
WvO> a whole bunch more that are related to file I/O.
WvO> Is there any difference in code efficiency, EXE size
WvO> and speed when the OS/2 API calls are used?
The C functions will eventually call the OS/2 API's you have shown. So
calling the OS/2 api is more direct, but not necessarily faster.
Some thoughts:
- The C calls are more standard (open() is POSIX, fopen() is ANSI,
for example), so your code will work with DOS, OS/2 16, OS/2 32,
PowerOS/2, etc without any changes.
- Once you use printf() (or cout <<), you have pretty much sucked
in the whole stream library anyway, so using DosOpen/DosRead, for
example, to make the EXE size small won't work, unless you avoid
using all CRT functions.
- Some CRT functions, because they do some sort of local buffering,
are faster (sometimes MUCH faster) than calling the direct OS/2
api. malloc() and fread()/fgets() come to mind. fread/fwrite can
be slower (it depends what you are doing), but are many times
faster -- and they are never very much slower even in the wort
case, so I just use them.
- The CRT functions are generally easier to use (they take fewer
arguments), more familiar to programmers, and are, therefore,
less error prone.
- All of the C runtimes I've seen so far must have "INITINSTANCE"
and "DATA MULTIPLE" in a *.DEF file when creating a DLL; if you
have advanced needs that require a "global dll", you can not use
*any* c runtime functions (except real simple ones like strcpy),
so you will have to use the direct OS/2 api's. It is not often
an application will have to create such a DLL.
- The code backing any OS/2 api is most likely written in C; so
being a hard-core pure MASM os/2 programmer may be fruitless.
WvO> Take mkdir() as an example. I don't need to set EA's when creating a
WvO> particular directory, so I could be using both
WvO> mkdir() and DosCreateDir().
My rule: If the CRT function will work, I use it. I only drop down to the
OS/2 api if I need to do something special (like allocating shared memory,
which malloc() won't do).
I don't know what compiler you're using, but IBM Cset++ has a "tiny
runtime" option (the /Rn switch) that works well for simple programs,
if it is EXE size you are worried about.
WvO> And the code doesn't have to be portable to other
WvO> operating systems.
So you say now...:-).
--- Maximus/2 2.02p1
* Origin: Sol 3/Toronto (905)858-8488 (1:259/414)SEEN-BY: 105/42 620/243 624/50 711/401 409 410 413 430 807 808 809 934 955 SEEN-BY: 712/407 515 628 704 713/888 800/1 7877/2809 @PATH: 259/414 400 99 250/702 3615/50 396/1 270/101 105/103 42 712/515 @PATH: 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.