public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: Nils Stec <nils.stec@gmail.com>
Cc: ELKS <linux-8086@vger.kernel.org>
Subject: Re: Cleaning up elkscmd and adding help text - Questions
Date: Fri, 27 Mar 2015 18:31:19 +0000	[thread overview]
Message-ID: <20150327183119.4f4bc5b3@www.etchedpixels.co.uk> (raw)
In-Reply-To: <55159A80.4040408@gmail.com>

On Fri, 27 Mar 2015 18:59:28 +0100
Nils Stec <nils.stec@gmail.com> wrote:

> Wow i really belive that writing this took some time... Thank you, this 
> gave me a lot of hints, do's and don'ts.
> 
> I read The Art of Unix Programming, but you showed me that i forgot a lot ;)
> 
> I think I'm going to rewrite my patches with all that things in mind, 
> will send them soon.

One thing that is not obvious

stderr is unbuffered, and this is required by the C language standard

That means that

   /* A function so we don't have two copies of the same string, and
      we don't go mad counting bytes */
   static int writes(int fd, const char *s) {
	return write(fd, s, strlen(s));
   }

   write(2, argv[0], strlen(argv[0]));
   writes(2, " broke.\n");

is actually better than fprintf. Not that performance matters here , if
you are optimising the performance of error reporting then you've almost
certainly got the wrong priorities.


In the FUZIX case we've shared several Kbytes of some key binaries by
carefully avoiding the use of malloc, stdio and floating point. The same
ought to be the case for ELKS although some of the other changes we do
like avoiding floating point and if possible division of long types is
much much less important as the 8086 has multiply/divide instructions
even if only 16bit ones.

Several of the elks tools do

     blah = malloc(somefixedsize)
     do stuff
     free(blah)

which for a utility which always needs the buffer except in error cases
is actually massively less efficient than simply doing

      static uint8_t blah[somefixedsize];



The v7 utilities are well worth reading for their elegance and efficiency
of memory usage. It's quite old style C so can be harder to read than
modern ANSI C, but the techniques used are frequently very clever indeed,
and some like the v7 implementation of "dd" are masterpieces.

Alan

  reply	other threads:[~2015-03-27 18:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27  8:19 Cleaning up elkscmd and adding help text - Questions Nils Stec
2015-03-27 13:19 ` Jody Bruchon
2015-03-27 14:10   ` Alan Cox
2015-03-27 16:17     ` Jody Bruchon
2015-03-27 18:19       ` MFLD
2015-03-27 18:26         ` Jody Bruchon
2015-03-27 18:52           ` MFLD
2015-03-27 22:19             ` Alan Cox
2015-03-28 15:35               ` LM
2015-03-27 18:41         ` Alan Cox
2015-03-27 17:59   ` Nils Stec
2015-03-27 18:31     ` Alan Cox [this message]
2015-03-27 13:54 ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150327183119.4f4bc5b3@www.etchedpixels.co.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-8086@vger.kernel.org \
    --cc=nils.stec@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox