I can read bytes from a FileStream with stream.ReadByte () but that does not
handle stdin. I can read from stdin with System.Console. In using
reader.Read() but it is 6x slower.
So how do I read bytes from stdin efficiently?
--
Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u 3 7000
Jon,
The comparison to reading from a file is comparing apples to oranges.
The mechanism might be the same, but you are in fact reading from two
separate sources which have different performance profiles.
I don't know if you can make it any faster, but you can try calling
GetStdHandle through the P/Invoke layer to see if you can get any better
results.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Jon Harrop" <jo*@ffconsulta ncy.comwrote in message
news:dL******** *************** *******@posted. plusnet...
>
I can read bytes from a FileStream with stream.ReadByte () but that does
not
handle stdin. I can read from stdin with System.Console. In using
reader.Read() but it is 6x slower.
So how do I read bytes from stdin efficiently?
--
Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u
On Jun 4, 5:37 pm, Jon Harrop <j...@ffconsult ancy.comwrote:
I can read bytes from a FileStream with stream.ReadByte () but that does not
handle stdin. I can read from stdin with System.Console. In using
reader.Read() but it is 6x slower.
So how do I read bytes from stdin efficiently?
Well, one problem is that Console.In doesn't handle bytes - it handles
*characters*. I would be somewhat wary of trying to pipe non-textual
information via Console.In. There may well be a sure-fire way of
getting it to work (and Console.OpenSta ndardInput would be my first
port of call) but I'd still be somewhat wary.
Is this in aid of optimising the sumcol (or sumfile, the name seems to
vary) benchmark?
Jon
Jon Skeet [C# MVP] wrote:
On Jun 4, 5:37 pm, Jon Harrop <j...@ffconsult ancy.comwrote:
>I can read bytes from a FileStream with stream.ReadByte () but that does not handle stdin. I can read from stdin with System.Console. In using reader.Read( ) but it is 6x slower.
So how do I read bytes from stdin efficiently?
Console.OpenSta ndardInput would be my first port of call...
That is exactly the answer I was looking for, thank you.
--
Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bernhard Kuemel |
last post by:
Hi!
I want to read/write commands and program input to/from /bin/bash
several times before I close the stdin pipe. However, reading
from cat hangs unless I first close the stdin pipe.
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# to open a file and write to file
# do
f=open('xfile.txt','w')
# this creates a file "object" and name it f.
# the second argument of open can be
|
by: Charlie Zender |
last post by:
Hi,
I have a program which takes the output filename argument from stdin.
Once the program knows the output filename, it tries to open it.
If the output file exists, the program asks the user to confirm
whether he really wants to overwrite the existing output file.
The problem is that the second read from stdin, to obtain the user
response whether to overwrite the existing output file, never
waits for the user's response. It's as if a...
|
by: eriwik |
last post by:
Hi,
I'm working on a small application which processes PNG-images and need
to read parts of them into structures and/or variables and I was
wondering what assumptions one can make about how the compiler places
things in memory.
Or more specific, I want to read the color-palette into a array of
structs with the following format:
|
by: James Dean |
last post by:
I create a new filestream and then i move i use the readbyte function
and the position function when required. These seem to be cripplingly
slow for some reason. This readbyte maybe is the problem. Do i need to
use a binaryReader with this in order for it to be faster?. I am
manipulating a compressed image file. Because i am reading in so many
bytes it makes it inefficient. Could somebody have a suggestion as how
to remedy this problem.
| |
by: Keith Kingsley |
last post by:
I'm new to C#, so please forgive me if this is elementary. I have a file
that consists of, say, one thousand (4-byte) floating points, and I'd like to
read it into an array of floats as efficiently as possible. In C/C++ I'd
simply malloc an array of bytes, read them into my allocated buffer, and cast
the pointer to the buffer as a pointer to a float. In C#, I can read in the
array of bytes like so:
FileStream fs = new...
|
by: Tonio Cartonio |
last post by:
I have to read characters from stdin and save them in a string. The
problem is that I don't know how much characters will be read.
Francesco
--
-------------------------------------
http://www.riscossione.info/
|
by: Markus Mayer |
last post by:
Hi folks.
I'm somewhat new to *nix programming and just ran into a problem. I have
to take user input from the terminal but like to constrain that to some
rules given, i.e. "numbers only" or "alphanumeric only" etc.
scanf would do, but I don't like the fact that wrong ('disallowed')
characters are visible and all that stuff. For that I need unbuffered
input. Since there seems to be no atomic function to do that I tried to
fiddle around...
|
by: sapsi |
last post by:
Hello,
I am using HadoopStreaming using a BinaryInputStream. What this
basically does is send a stream of bytes ( the java type is : private
byte bytes) to my python program.
I have done a test like this,
while 1:
x=sys.stdin.read(100)
if x:
print x
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |