Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Nov 2000 00:08:16 +0100
From:      Ernst de Haan <ernst@jollem.com>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        Sebastiaan van Erk <sebster@sebster.com>, Zero Sum <count@shalimar.net.au>, freebsd-questions@FreeBSD.ORG
Subject:   Re: argument list too long
Message-ID:  <20001117000816.B15150@c187104187.telekabel.chello.nl>
In-Reply-To: <20001116143843.S830@fw.wintelcom.net>; from bright@wintelcom.net on Thu, Nov 16, 2000 at 02:38:43PM -0800
References:  <20001116091607.A97857@sebster.com> <00111621362707.00522@shalimar.net.au> <20001116122313.A69018@sebster.com> <00111700205500.61931@shalimar.net.au> <20001116145641.A22842@sebster.com> <20001116105654.G830@fw.wintelcom.net> <20001116231731.A14470@c187104187.telekabel.chello.nl> <20001116143843.S830@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Alfred,

Alfred Perlstein wrote:
> * Ernst de Haan <ernst@jollem.com> [001116 14:18] wrote:
> > > Can you please suggest a reasonable limit to the argument list?
> > 
> > You don't get the point. In Sebastiaan's opinion there should be no fixed
> > limit. I assume you never worked with variable-size data types? Linked lists
> > are the simplest form. But so are resizing arrays.
> 
> I'd like to see what Linux does when you try to run this:
> 
> ls -l `find /`

I don't know about Leenucks. I don't have it running here.

> Assuming it doesn't crash your Linux box, go complain to Linus
> about expanding the max system arglist size, if it does crash
> your box, well then I guess you don't have anything to complain
> about, do you?

Why are you coming up with Linux and Linus? What do those have to do with the
problem? (or `challenge' rather!) We're talking about FreeBSD here, remember?
Do you understand that the data type used to hold the argument list for a
program can be extended if needed? Have you ever worked with linked lists

> There exists kernel APIs for determining the max arg list size.

Why impose an arbitrary restriction? In the old days, with limited memory, the
small overhead imposed by using variable sized data structures may have been
very important, but today we have the opportunity to improve the quality of
FreeBSD by making use of modern features and techniques.

Perhaps a small code example will help. Suppose this is our old design:

   int i;
   int MAX_ARGUMENTS = 2048;
   char *arguments[] = (char **) malloc (MAX_ARGUMENTS * sizeof(char *));

   :

   for (i=0; i<MAX_ARGUMENTS && parser.hasMoreTokens(); i++) {
      char *s = parser.nextToken();
      arguments[i] = (char *) malloc(strlen(s) * sizeof(char));
      strcpy(arguments[i], s);
   }

   if (i == MAX_ARGUMENTS) {
      // crash out
   }

You could do something more complex:

   int ARGUMENTS_PER_BLOCK = 128;
   struct ArgumentBlock {
      char *arguments[];
      ArgumentBlock *next;
   };

   typedef ArgumentBlock_t struct ArgumentBlock;

   ArgumentBlock_t firstBlock;
   ArgumentBlock_t currentBlock;

   :

   for (i=0; parser.hasMoreTokens(); i++) {
      char *s = parser.nextToken();

      // If the current block is full: Create a new block, and make it the
      // current

      // Copy the stuff into the current block
   }

   // Never crash out, unless we run out of memory :)

The code is meant as an illustration, it's been a few years since I've done
C, but I think any C programmer will see what I mean :)

> Coders that assume inifinite memory are fooling themselves and
> need to learn how to code properly.

Sure, but so are coders that assume very limited memory! :)


Ernst


> -- 
> -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org]
> "I have the heart of a child; I keep it in a jar on my desk."
> 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001117000816.B15150>