Standard efficiency

This is a discussion on Standard efficiency within the C Programming forums, part of the General Programming Boards category; Well, I have been developing my own implementation of the C Standard for UNIX platforms (only tested on Linux, though). ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85

    Standard efficiency

    Well, I have been developing my own implementation of the C Standard for UNIX platforms (only tested on Linux, though). It's going very well and I'm very glad that I managed to implement the whole stdio library except for 'printf and its friends (sprintf, scanf...)', since this will be a really tough work. In fact, I was looking to find an already available Open-source implementation.

    I must say that the hard part was starting with the FILE structure and, eventually, having to steadily modify it to fit the needs of each function, such as ungetc and etcetera. Implementing a wrapper to kernel calls was also tough, but - hey - I'm alive.

    What I've come to understand with this "hobby of mine" is that, while following the standard might be portable, it seems to hit performance, since it seems to me that the standard implementations are merely wrappers (with additional features which slow it down) to the 'real' functions.

    So if we know that we will be targeting a given platform and that our code doesn't have to compile on another, does it seem reliable to directly use an Operating System's API and System Calls? Sure it'll break portability, but it will increase performance.


    And I think that this all happens because the maintainers of the operating systems do not implement themselves the standard. AFAIK it was born in UNIX and everything should support it natively! But that's just silly me who is angry at some companies.

    Also, given that I wanted to have printf and its friends working, can someone point me to an available implementation? I'd look for every implementation-specific functions such as writing/reading operations, file structure manipulation and others and replace them with my own functions.

    Thanks, sorry to bug you,

    Jorl17

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Premature optimization is the root of all evil. Your worries are misplaced. The overhead the "wrapper" part of the standard library introduces is irrelevant 99.99% of the time or more. Also, the standard library doesn't consist only of wrappers. For example, fgetc()? That's not a wrapper. It doesn't simply emit a read() call into a buffer of one character. Instead it manages the buffer in the FILE stream and is quite efficient.
    Let's assume fgetc didn't exist. What would you do when you want to read a file byte by byte? Emit read() calls for every character? Well, your attempt to improve performance has just shot performance to hell and beyond. Perhaps allocate a buffer and make one big read() call into it? Congratulations, you've reimplemented fgetc(). Of course, you have to test it and maintain it now, instead of leaving that to your compiler vendor.
    The standard library is anything but a wrapper. It's a great collection of high-quality, highly tuned utility functions that make programming a lot easier.

    Any reason you posted this in C++, by the way? You seem to be talking about the C standard library.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    You are absolutely right, in fact, that's what I do in my implementation ( go figure).

    I posted this in C++ because I'm an idiot, I am really sorry for that, if someone can, please move it... (The real reason is that I am also trying to implement my STL, but I quit talking about it...)

    Thanks. And I must say that I _DO_ use the standard library, all the time. The problem is that I have been hitting some bugs on mingw's std library for win32, which have forced me to implement something myself, and that made me check my big std library again. I'm all standards when I can, that's why most of my apps only use cross-platform toolkits.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,185
    Moved to C Programming forum.

    Quote Originally Posted by Jorl17
    The problem is that I have been hitting some bugs on mingw's std library for win32, which have forced me to implement something myself
    Consider documenting and reporting each bug, possibly with a patch if you are able to fix it.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array initialization & C standard
    By jim mcnamara in forum C Programming
    Replies: 2
    Last Post: 09-12-2008, 04:25 PM
  2. Efficiency with c++
    By pastitprogram in forum C++ Programming
    Replies: 17
    Last Post: 08-08-2008, 12:18 PM
  3. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 01:02 AM
  4. C/C++ standard
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-06-2003, 04:22 AM
  5. standard language, standard compiler?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-03-2001, 05:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21