Click here to Skip to main content
15,918,976 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: how to convert plural word to singular? Pin
73Zeppelin14-Nov-08 2:18
73Zeppelin14-Nov-08 2:18 
AnswerRe: how to convert plural word to singular? Pin
User 171649214-Nov-08 1:39
professionalUser 171649214-Nov-08 1:39 
QuestionTable comparison material Pin
aggressor_us12-Nov-08 13:29
aggressor_us12-Nov-08 13:29 
AnswerRe: Table comparison material Pin
Member 419459315-Nov-08 12:22
Member 419459315-Nov-08 12:22 
GeneralRe: Table comparison material Pin
aggressorus17-Nov-08 6:09
aggressorus17-Nov-08 6:09 
GeneralRe: Table comparison material Pin
Member 419459317-Nov-08 12:40
Member 419459317-Nov-08 12:40 
GeneralRe: Table comparison material Pin
aggressorus9-Dec-08 7:13
aggressorus9-Dec-08 7:13 
QuestionBuffering data for delimiter seperated blocks (theoretical question) Pin
invictus311-Nov-08 11:29
invictus311-Nov-08 11:29 
Hi
There is a question I have been wondering about for ages and I was hoping someone could give me an answer to rest my mind.

Lets assume I have an input stream (like a file/socket/pipe) and want to parse the incoming data. Lets assume each block of incoming data is split by a newline like most common internet protocols. This just however just as well be parsing html/xml or any other smart data structure. The point is that the data is split into logical blocks by a delimiter rather than a fixed length. How can I buffer the data to wait for the delimiter to appear?

The question seems simple enough: just have a large enough byte/char array to fit the entire thing.

But what if the delimiter come after the fixed size buffer is full? This is actually a question about how to fit a dynamic block of data in a fixed size block. I can only really think of a few alternatives:

1) increase the buffer size when needed. This may require heavy memory reallocation, and may lead to resource exhaustion from specially crafted streams (or perhaps even denial of service in the case of sockets where we want to protect ourselves against exhaustion attacks and drop connections that try to exhaust resources...and an attacker starts sending fake, oversized, packets to trigger the protection)
2) start overwriting old data by using a circular buffer. Perhaps not an ideal method since the logical block would become incomplete
3) dump new data when the buffer is full. However, this way the delimiter will never be found so this choice is obviously not a good option
4) just make the fixed size buffer damn large and assume all incoming logical data blocks is within its bounds...and if ever full just interpret the full buffer as a logical block...

In either case I feel we must just assume that the logical blocks will never exceed a certain size...

Any thoughts on this topic? Obviously it must be a way since the higher level languages offer some sort of buffering mechanisms with their readLine() stream methods.

Is there any "best way" to solve this or is there always a tradeoff? I really appreciate all thoughts and ideas on this topic since this question has been haunting me everytime I have needed to write a parser of some sort.
AnswerRe: Buffering data for delimiter seperated blocks (theoretical question) Pin
Arash Partow12-Nov-08 0:57
Arash Partow12-Nov-08 0:57 
AnswerRe: Buffering data for delimiter separated blocks (theoretical question) Pin
Alan Balkany12-Nov-08 3:37
Alan Balkany12-Nov-08 3:37 
QuestionConstructing a convex hull. Pin
Member 419459311-Nov-08 8:56
Member 419459311-Nov-08 8:56 
AnswerRe: Constructing a convex hull. Pin
Arash Partow12-Nov-08 0:45
Arash Partow12-Nov-08 0:45 
GeneralRe: Constructing a convex hull. Pin
Member 419459312-Nov-08 4:58
Member 419459312-Nov-08 4:58 
GeneralRe: Constructing a convex hull. Pin
Member 419459312-Nov-08 5:13
Member 419459312-Nov-08 5:13 
QuestionLimit finding Pin
Hadi Dayvary6-Nov-08 10:19
professionalHadi Dayvary6-Nov-08 10:19 
AnswerRe: Limit finding Pin
73Zeppelin6-Nov-08 10:26
73Zeppelin6-Nov-08 10:26 
GeneralRe: Limit finding Pin
Hadi Dayvary6-Nov-08 10:37
professionalHadi Dayvary6-Nov-08 10:37 
GeneralRe: Limit finding Pin
BobInNJ6-Nov-08 12:57
BobInNJ6-Nov-08 12:57 
GeneralRe: Limit finding Pin
bulg6-Nov-08 13:59
bulg6-Nov-08 13:59 
GeneralRe: Limit finding Pin
73Zeppelin6-Nov-08 21:13
73Zeppelin6-Nov-08 21:13 
GeneralRe: Limit finding Pin
Hadi Dayvary7-Nov-08 9:43
professionalHadi Dayvary7-Nov-08 9:43 
GeneralRe: Limit finding Pin
73Zeppelin7-Nov-08 18:44
73Zeppelin7-Nov-08 18:44 
GeneralOff-Topic Pin
soap brain8-Nov-08 1:16
soap brain8-Nov-08 1:16 
GeneralRe: Off-Topic Pin
User 17164928-Nov-08 1:38
professionalUser 17164928-Nov-08 1:38 
GeneralRe: Off-Topic Pin
soap brain8-Nov-08 1:48
soap brain8-Nov-08 1:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.