Re: [AD] implementing seek |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: "Coordination of admins/developers of the game programming library Allegro" <alleg-developers@xxxxxxxxxx>
- Subject: Re: [AD] implementing seek
- From: Matthew Leverton <meffer@xxxxxxxxxx>
- Date: Wed, 7 Apr 2010 13:23:31 -0500
On Wed, Apr 7, 2010 at 6:02 AM, Peter Wang <novalazy@xxxxxxxxxx> wrote:
> On 2010-04-07, Matthew Leverton <meffer@xxxxxxxxxx> wrote:
>> I agree. But what about:
>>
>> where 'pos' is always pointing to the next position because the file
>> format stored the length?
>
> It imposes too many constraints on the loader implementation.
> You couldn't use SEEK_END at all, or even SEEK_SET with an absolute
> offset (as you mention).
>
Again, no arguments. The SEEK_SET could be worked around, but SEEK_END
would still be troublesome.
> For a robust solution, the user should pass an ALLEGRO_FILE handle that
> provides a view of exactly one file.
>
> The function you alluded to earlier was cleaner:
>
> ALLEGRO_FILE *al_fopen_slice(ALLEGRO_FILE *f, size_t length);
>
> perhaps combined with memory buffering as an option, for underlying
> streams that don't understand backward seeks. Maybe also mix in
> read/write permissions.
>
I just thought that introducing a new file handle may cause problems
due to concurrent usage. One example:
f1 = al_fopen("foo.txt", "r");
f2 = al_fopen_slice(f1, 100);
al_fgetc(f2);
al_ftell(f1); // 0 or 1?
al_fclose(f2);
al_ftell(f1); // 0, 1, or 100?
I have no problem with saying that slices could not be used
concurrently with the source file. However, upon closing the slice,
what state would the source file be at?
--
Matthew Leverton