GP32 Streams


pea

developer
Joined
Oct 3, 2004
Messages
1,089
Age
45
Location
New Zealand
Website
www.projectitis.com
Hi all,

I am currently writing a stream library (memory stream, not file stream) capable of holding arbitrary-length data. It works with chunks of a set size. Once a chunk is filled, a new one is allocated from the memory. It is used for loading data of unknown length, and data that needs its length altered all the time ,such as text files (notepad style).

Just some questions -
1) Surely this has been done already? Anyone know of any good stream lib for c?
2) What is a good size for the 'chunks' of memory? 1k?
 
Ok, I got my stream class up and working. You can:

create a stream (empty)
write to the stream (expands it as needed)
read from the stream
seek to a position (SET, CUR and END supported)
clear the stream
load data from smc directly to stream
copy from one stream to another

Still to do:
Insertion of data
Deletion of data

Here is a snippet on how to use it :)
Code:
tGP_stream *stream;
int res;
char *buffer;

// Create a stream
stream = gp_streamCreate();
	
// Load part1 from the SMC
gp_streamReadFromFile( stream, "dev0:\\GPMM\\part1.txt", &res ); 
// Append part2 from the SMC
gp_streamReadFromFile( stream, "dev0:\\GPMM\\part2.txt", &res );
  
// Create a buffer the same size as the stream
buffer = (char*)malloc( stream->size );
// Go the the start of the stream
gp_streamSeek( stream, 0, STREAM_SET, &res );
// Read the stream into the buffer
size = gp_streamRead( stream, buffer, stream->size, &res);

Woot!
 
Add (or use as main interface) a standard C set for it.. ie: fopen, use sopen perhaps? Thus making code ports and writing easy.

A "mem filesystem" fitting the bill exists in the Small language distribution, but its not hard to write so have fun :)

jeff
 
Back
Top