Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #11885 > unrolled thread
| Started by | Максим Фомин <maxim@maxim-fomin.ru> |
|---|---|
| First post | 2011-10-19 12:26 -0700 |
| Last post | 2012-01-07 14:37 -0500 |
| Articles | 3 on this page of 43 — 24 participants |
Back to article view | Back to comp.lang.c
Analogue of ReadLine() in C Максим Фомин <maxim@maxim-fomin.ru> - 2011-10-19 12:26 -0700
Re: Analogue of ReadLine() in C China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-19 13:05 -0700
Re: Analogue of ReadLine() in C China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-19 20:50 -0700
Re: Analogue of ReadLine() in C Seebs <usenet-nospam@seebs.net> - 2011-10-20 07:42 +0000
Re: Analogue of ReadLine() in C China Blue Corn Chips <chine.bleu@yahoo.com> - 2011-10-20 02:51 -0700
Re: Analogue of ReadLine() in C gazelle@shell.xmission.com (Kenny McCormack) - 2011-10-20 12:52 +0000
Re: Analogue of ReadLine() in C "BartC" <bc@freeuk.com> - 2011-10-20 14:31 +0100
Re: Analogue of ReadLine() in C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-10-20 08:05 -0700
Re: Analogue of ReadLine() in C gazelle@shell.xmission.com (Kenny McCormack) - 2011-10-20 15:15 +0000
Re: Analogue of ReadLine() in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-20 16:50 +0100
Re: Analogue of ReadLine() in C "BartC" <bc@freeuk.com> - 2011-10-20 23:23 +0100
Re: Analogue of ReadLine() in C Keith Thompson <kst-u@mib.org> - 2011-10-20 15:34 -0700
Re: Analogue of ReadLine() in C Ian Collins <ian-news@hotmail.com> - 2011-10-21 14:10 +1300
Re: Analogue of ReadLine() in C "BartC" <bc@freeuk.com> - 2011-10-21 10:30 +0100
Re: Analogue of ReadLine() in C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-10-21 05:59 -0700
Re: Analogue of ReadLine() in C Keith Thompson <kst-u@mib.org> - 2011-10-21 10:58 -0700
Re: Analogue of ReadLine() in C "BartC" <bc@freeuk.com> - 2011-10-22 20:00 +0100
Re: Analogue of ReadLine() in C Ian Collins <ian-news@hotmail.com> - 2011-10-23 08:09 +1300
Re: Analogue of ReadLine() in C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-10-22 23:55 -0700
Re: Analogue of ReadLine() in C Ian Collins <ian-news@hotmail.com> - 2011-10-21 08:34 +1300
Re: Analogue of ReadLine() in C Seebs <usenet-nospam@seebs.net> - 2011-10-20 17:57 +0000
Re: Analogue of ReadLine() in C Markus Wichmann <nullplan@gmx.net> - 2011-10-23 23:03 +0200
Re: Analogue of ReadLine() in C Acid Washed China Blue Jeans <chine.bleu@yahoo.com> - 2011-10-24 00:31 -0700
Re: Analogue of ReadLine() in C Richard Damon <news.x.richarddamon@xoxy.net> - 2011-10-24 08:10 -0400
Re: Analogue of ReadLine() in C 88888 Dihedral <dihedral88888@googlemail.com> - 2011-10-19 14:04 -0700
Re: Analogue of ReadLine() in C Kaz Kylheku <kaz@kylheku.com> - 2011-10-19 21:52 +0000
Re: Analogue of ReadLine() in C Ike Naar <ike@iceland.freeshell.org> - 2011-10-19 22:34 +0000
Re: Analogue of ReadLine() in C pete <pfiland@mindspring.com> - 2011-10-19 19:02 -0400
Re: Analogue of ReadLine() in C pete <pfiland@mindspring.com> - 2011-10-20 00:36 -0400
Re: Analogue of ReadLine() in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-20 00:11 -0700
Re: Analogue of ReadLine() in C Максим Фомин <maxim@maxim-fomin.ru> - 2011-10-20 01:59 -0700
Re: Analogue of ReadLine() in C James Kuyper <jameskuyper@verizon.net> - 2011-10-20 06:57 -0400
Re: Analogue of ReadLine() in C Markus Wichmann <nullplan@gmx.net> - 2011-10-20 18:40 +0200
Re: Analogue of ReadLine() in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-20 18:20 +0100
Re: Analogue of ReadLine() in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-10-21 08:58 +0000
Re: Analogue of ReadLine() in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-21 19:12 +0100
Re: Analogue of ReadLine() in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-21 19:35 +0100
Re: Analogue of ReadLine() in C "io_x" <a@b.c.invalid> - 2011-10-22 18:58 +0200
Re: Analogue of ReadLine() in C David Thompson <dave.thompson2@verizon.net> - 2011-10-28 01:34 -0400
Re: Analogue of ReadLine() in C Michael Angelo Ravera <maravera@prodigy.net> - 2011-10-20 13:32 -0700
Re: Analogue of ReadLine() in C James Kuyper <jameskuyper@verizon.net> - 2011-10-20 16:42 -0400
Re: Analogue of ReadLine() in C "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-10-20 16:47 -0400
Re: Analogue of ReadLine() in C Shao Miller <sha0.miller@gmail.com> - 2012-01-07 14:37 -0500
Page 3 of 3 — ← Prev page 1 2 [3]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2011-10-20 16:42 -0400 |
| Message-ID | <4EA0879C.6010904@verizon.net> |
| In reply to | #11922 |
On 10/20/2011 04:32 PM, Michael Angelo Ravera wrote: ... > The reason that you code fails is that you can't generally realloc > what you haven't [m|c|0]alloc'd. What's the 0 for? 0alloc'd? You are also allowed to realloc() a null pointer, or a pointer returned by a previous successful call to realloc() that has not yet been free()d or successfully realloc()d again. As far as I can see, those are the only two things this code ever realloc()s. Have I missed something?
[toc] | [prev] | [next] | [standalone]
| From | "Morris Keesan" <mkeesan@post.harvard.edu> |
|---|---|
| Date | 2011-10-20 16:47 -0400 |
| Message-ID | <op.v3n3012b5qv6o3@toshiba-laptop> |
| In reply to | #11922 |
On Thu, 20 Oct 2011 16:32:06 -0400, Michael Angelo Ravera
<maravera@prodigy.net> wrote:
> The reason that you code fails is that you can't generally realloc what
> you haven't [m|c|0]alloc'd.
Wrong. From the C99 standard, ISO/IEC 9899:1999 (E)
7.20.3.4 The realloc function
Synopsis
#include <stdlib.h>
void *realloc(void *ptr, size_t size);
...
If ptr is a null pointer, the realloc function behaves like the
malloc function for the specified size.
--
Morris Keesan -- mkeesan@post.harvard.edu
[toc] | [prev] | [next] | [standalone]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Date | 2012-01-07 14:37 -0500 |
| Message-ID | <jea707$9k8$1@dont-email.me> |
| In reply to | #11885 |
On 10/19/2011 15:26, Максим Фомин wrote:
> I need function similar to ReadLine() in any other language.
> The program below fails[1] when data more then LAG_SIZE is passed
>
> [...code...]
I guess the biggest line you can handle is limited by the biggest
contiguous range of memory that you can allocate. Maybe you could
allocate as large a buffer as possible when your program starts, then
each time you read a line, try to fill the buffer from the beginning and
worry about what happens when you don't find a newline before that
buffer has been filled.
Here's a silly little bit of code to allocate a large buffer, which is
also available at http://codepad.org/nLoYZzej:
/* For use with C89 */
#include <stddef.h>
#include <stdlib.h>
static void * biggest_buf(void);
int main(void) {
char * foo;
foo = biggest_buf();
free(foo);
return EXIT_SUCCESS;
}
static void * biggest_buf(void) {
char * big_buf;
size_t max_size, big_size, test_size, highest_test;
/* Find the maximum size_t */
max_size = 0;
--max_size;
switch (1) while (1) {
/* big_size < test_size < highest_test */
big_buf = malloc(test_size);
if (!big_buf) {
if (test_size == big_size) {
/* Maximum allocation has changed. Start over */
case 1:
test_size = highest_test = max_size;
big_size = 0;
continue;
}
/*
* We couldn't allocate a bigger buffer than last time.
* Split the difference and try a smaller allocation
*/
highest_test = test_size;
test_size = (test_size - big_size) / 2 + big_size;
continue;
}
/* Check if we've found the biggest allocation */
if (test_size == big_size) {
/* All done */
break;
}
/* Otherwise, we might be able to allocate more */
free(big_buf);
big_size = test_size;
test_size = (highest_test - big_size) / 2 + big_size;
continue;
}
return big_buf;
}
- Shao Miller
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | comp.lang.c
csiph-web