Re: glib outstanding stuff



On Thu, Oct 05, 2000 at 05:38:37PM +0100, Trog wrote:
> I don't disagree, but it isn't very efficient, and has limited
> usefulness.

	Sure it is efficient for smaller file cases.

> Wouldn't it be better to generalise it so that we could
> efficiently handle large files as well as small ones?

	Large files and small ones have a different semantic, as do
files that are line or field oriented.

> Wouldn't a readline() type interface (in GIOChannel) and an mmap()
> based interface cover a much larger set of requirements?

	readline() fails utterly on a file that isn't line oriented.
mmap() changes the file contents.
	Say I have a non-huge data file.  I want to do operations on the
data and get a munged result.  I don't want to affect the actual file
contents, so mmap() is out.  I don't necessarily have a line-oriented
file, so readline() is out (or really, it's equivalent if there are *no*
newlines).  The proper "read a chunk, see if we can parse some of it,
otherwise read more chunk, try parsing again, lather, rinse, repeat"
routine is non-trivial and overkill in this case.  A simple "get
contents, strstr() into contents, munge some, print" or whatnot is much
easier on the programmer.
	For larger files, especially if the operation supports inline
work, the readline() or readchunk() approach is of course superior.  And
in-place file changes can certainly use mmap().
	It might be a worthwhile addition to provide that
infrastructure, either seperatly or as part of a GIOChannel action.
Say:

g_parse_file_inline(const gchar *filename,
                    GParseFunc parse_current_buffer,
                    gpointer user_data);
g_parse_file_by_line(const gchar *filename,
                     GParseFunc parse_current_line,
                     gpointer user_data);
g_parse_fd_inline(gint fd,
                  GParseFunc parse_current_buffer,
                  gpointer user_data);
g_parse_fd_by_line(gint fd,
                   GParseFunc parse_current_line,
                   gpointer user_data);

(or whatever the GClosure equivalent would be).
	However, you're getting into GScanner territory here as well.

Joel

-- 

"Heav'n hath no rage like love to hatred turn'd, nor Hell a fury,
 like a woman scorn'd."
        - William Congreve

			http://www.jlbec.org/
			jlbec evilplan org




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]