www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Overhead when using a C library

reply "Jeremy DeHaan" <dehaan.jeremiah gmail.com> writes:
Hey guys!

I am working on a binding for D, and am almost finished! I 
started to think of some things I might like to work on to 
improve the binding after I get everything working, and one of 
the things I thought of was rewriting certain parts to use only D 
code instead of making calls to the C functions. Is there any 
kind of performance overhead in using C libraries to interact 
with your D program? If it isn't going to offer much performance 
gain then I probably don't need to bother writing extra code.

Thanks as usual!
Mar 13 2013
next sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 03/14/2013 01:48 AM, Jeremy DeHaan wrote:
 Hey guys!

 I am working on a binding for D, and am almost finished! I started to
 think of some things I might like to work on to improve the binding
 after I get everything working, and one of the things I thought of was
 rewriting certain parts to use only D code instead of making calls to
 the C functions. Is there any kind of performance overhead in using C
 libraries to interact with your D program? If it isn't going to offer
 much performance gain then I probably don't need to bother writing extra
 code.

 Thanks as usual!
There is no additional overhead (though the D compiler will not be able to inline C functions, whereas an identical D function may be inlined.)
Mar 13 2013
next sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 03/14/13 01:52, Timon Gehr wrote:
 On 03/14/2013 01:48 AM, Jeremy DeHaan wrote:
 I am working on a binding for D, and am almost finished! I started to
 think of some things I might like to work on to improve the binding
 after I get everything working, and one of the things I thought of was
 rewriting certain parts to use only D code instead of making calls to
 the C functions. Is there any kind of performance overhead in using C
 libraries to interact with your D program? If it isn't going to offer
 much performance gain then I probably don't need to bother writing extra
 code.
There is no additional overhead (though the D compiler will not be able to inline C functions, whereas an identical D function may be inlined.)
Like Timon said - there's is zero overhead. Even the inlining limitation only applies to /some/ compilers. [1] xlanginline1.d: extern extern(C) int c(); int main() { return 2*c(); } xlanginline2.c: int c() { return 21; }; compiled with GDC + -flto: 08049820 <_Dmain>: 8049820: 55 push %ebp 8049821: b8 2a 00 00 00 mov $0x2a,%eax 8049826: 89 e5 mov %esp,%ebp 8049828: 5d pop %ebp 8049829: c3 ret artur [1] and versions, unfortunately.
Mar 14 2013
prev sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Thursday, 14 March 2013 at 00:52:41 UTC, Timon Gehr wrote:
 On 03/14/2013 01:48 AM, Jeremy DeHaan wrote:
 Hey guys!

 I am working on a binding for D, and am almost finished! I 
 started to
 think of some things I might like to work on to improve the 
 binding
 after I get everything working, and one of the things I 
 thought of was
 rewriting certain parts to use only D code instead of making 
 calls to
 the C functions. Is there any kind of performance overhead in 
 using C
 libraries to interact with your D program? If it isn't going 
 to offer
 much performance gain then I probably don't need to bother 
 writing extra
 code.

 Thanks as usual!
There is no additional overhead (though the D compiler will not be able to inline C functions, whereas an identical D function may be inlined.)
A decent link-time optimiser will be able to do the inlining where appropriate. gdc can be compiled with lto enabled, as Artur shows in his reply.
Mar 14 2013
prev sibling parent "Andrea Fontana" <nospam example.com> writes:
On Thursday, 14 March 2013 at 00:48:53 UTC, Jeremy DeHaan wrote:
 Hey guys!

 I am working on a binding for D, and am almost finished!
Are you going to publish this binding? Which library?
Mar 14 2013