which is faster: WinApi or C Runtime?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
tjandracom
Level 2
Level 2
Posts: 11
Joined: Mon Sep 08, 2008 12:53 am

which is faster: WinApi or C Runtime?

Post by tjandracom »

which is faster in Wine?

WinApi functions such as: CreateFile(), ReadFile(), WriteFile(), CloseFile(), HeapAlloc(), HeapRealloc(), etc.
vs.
C Runtime functions: fopen(), fread(), fwrite, fclose(), malloc(), etc.

if i develop an application to be run in Wine, should i use WinApi functions, or
C Runtime functions?
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Post by oiaohm »

If you are using pure C runtime you really need to consider if you should be using wine at all. There are more and more ways to go native.

Currently C runtime ways are faster. Mostly because optimisation has not been done on CreateFile() and the like instead they just wrap to fopen() and so on in glibc. Wrapping has a price.

Sorry to say the exact other way to windows. Its one place wine is a mirror image. If you go the C runtime path you will take a hit on windows. If you go the WinAPI path you take a hit on wine.
jeffz
Level 5
Level 5
Posts: 345
Joined: Thu Mar 13, 2008 10:03 pm

Post by jeffz »

oiaohm wrote:If you are using pure C runtime you really need to consider if you should be using wine at all. There are more and more ways to go native.

Currently C runtime ways are faster. Mostly because optimisation has not been done on CreateFile() and the like instead they just wrap to fopen() and so on in glibc. Wrapping has a price.

Sorry to say the exact other way to windows. Its one place wine is a mirror image. If you go the C runtime path you will take a hit on windows. If you go the WinAPI path you take a hit on wine.
It really depends on what this application is going to be doing and how often. Could be a case of premature optimization.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: which is faster: WinApi or C Runtime?

Post by vitamin »

tjandracom wrote:which is faster in Wine?

WinApi functions such as: CreateFile(), ReadFile(), WriteFile(), CloseFile(), HeapAlloc(), HeapRealloc(), etc.
vs.
C Runtime functions: fopen(), fread(), fwrite, fclose(), malloc(), etc.

if i develop an application to be run in Wine, should i use WinApi functions, or
C Runtime functions?
If this is windows program then win32 api will be faster. Because Wine's msvcrt is written on top of the win32 api. And does not call glibc functions directly.
tjandracom
Level 2
Level 2
Posts: 11
Joined: Mon Sep 08, 2008 12:53 am

Post by tjandracom »

oiaohm wrote:If you are using pure C runtime you really need to consider if you should be using wine at all. There are more and more ways to go native.
i still need the application to run in windows.
vitamin wrote:If this is windows program then win32 api will be faster. Because Wine's msvcrt is written on top of the win32 api. And does not call glibc functions directly.
then i can conclude that i should use win32api instead of msvcrt, whether running in Windows or Wine, isn't it?
3vi1
Level 4
Level 4
Posts: 125
Joined: Sun Feb 24, 2008 8:24 pm

Post by 3vi1 »

tjandracom wrote:i still need the application to run in windows.
I'm not sure what you're intending the app to do, but have you considered writing it in C# - and running the exe under Mono in Linux? I've played around with it, and it's even possible to get the same GUI working on both if you use the GTK libs.

-J
tjandracom
Level 2
Level 2
Posts: 11
Joined: Mon Sep 08, 2008 12:53 am

Post by tjandracom »

3vil wrote:I'm not sure what you're intending the app to do, but have you considered writing it in C# - and running the exe under Mono in Linux?
i'm new to linux, and i just migrate for a couple months from windows. Office application is not a problem because there is OpenOffice, but my written application is still running in windows. it runs well under Wine, but the performance is not so good. i planned to re-write my application to native linux, but it will take some time (for me to learn how to write linux application). for temporary, i only want to patch up the existing application to run a little bit faster in Wine.
Marcel W. Wysocki

which is faster: WinApi or C Runtime?

Post by Marcel W. Wysocki »

On Sat, 13 Sep 2008 01:04:48 -0500
"tjandracom" <[email protected]> wrote:
3vil wrote:
I'm not sure what you're intending the app to do, but have you considered writing it in C# - and running the exe under Mono in Linux?
i'm new to linux, and i just migrate for a couple months from windows. Office application is not a problem because there is OpenOffice, but my written application is still running in windows. it runs well under Wine, but the performance is not so good. i planned to re-write my application to native linux, but it will take some time (for me to learn how to write linux application). for temporary, i only want to patch up the existing application to run a little bit faster in Wine.



i strongly suggest you to write your app using the standard C library.
in some cases you have to use #ifdef s , esp when a func would usually
expect a unix permission mask for a file operation.
but after all. its a standard library.. and you will do good for your program
to use it. it might run on other platforms as well.
http://en.wikipedia.org/wiki/C_standard_library

--
Marcel W. Wysocki <[email protected]>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-us ... chment.pgp
Locked