tags:

views:

380

answers:

6

Are there any stdin input length limitations (in amount of input or input speed)?

+1  A: 

There aren't any length limits on stdin. If you can't receive large amounts of data it's your code that creates the problems.

sth
and any SPEED of sending Data limits?
Blender
+1  A: 

According to everyone's other favorite Q&A site:

There shouldn't be a limit to the stream size (whether that's stdin or another). What you might want to check however, is where you store these characters ... Is there enough space to store them all ?

Try just code like this (without storing !) :

    int c = 0;
    do {
        c = getc(stdin);
        printf("%c", (char) c);
    } while (c != EOF);           /* <--- or another terminator value */

and see whether it has the same restriction.

Justin Ethier
I hope you're referring to "expert sex change" tongue-in-cheek. I don't think I've _ever_ seen a useful answer on that site.
paxdiablo
Yeah, I've got no love for that site either. But sometimes I will stumble across a useful answer on there... with any luck they will gradually be migrated to SO one question at a time :)
Justin Ethier
This is the standard anti-pattern for reading a file. Please look up how to read a file without using an explicit test for EOF after the read. This (like the standard anti-pattern) will print the EOF character which is practically never what you want. Why give a C answer?
Martin York
The code is just an example. Please feel free to edit it as needed.
Justin Ethier
A: 

There are limits in the speed of transfer. In general, they are approximately the same as any "UNIX" pipe. There are more efficient mechanisms offered by most operating systems, but pipes are quite fast... assuming you're not using printf & such.

Pestilence
+2  A: 

No. stdin has no limits on length or speed.

If you want to get gigabytes of data via stdin you can, and your computer will supply it as fast as it can.

egrunin
Downvoted without explanation?
egrunin
+1  A: 

It probably depends on the stdin driver !

stdin (as a concept) has no limitation.

I expect that kernel developers (of any systems) have made some design choices which add limitations.

jag
+1  A: 

Try it:

The yes unix command outputs lines of y endlessly. Pipe it to a C program that just reads stdin and puts it on stdout (e.g. cat, but tr 'y' 'y' also works). Wait until cat crashes or your patience reaches its limit:

yes | cat

About the speed factor, limits are not determined by language or OS but by hardware (CPU, RAM, hard-disk, SATA, network, ...)

mouviciel
There really is a command for everything.
invariant
It is used when another command needs confirmation which cannot be disabled (like a hardcoded `rm -i`).
mouviciel