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

Re: Sv: Sv: Sv: PenguinFile



Bjarke Hammersholt Roune schrieb:

> Win32 does not support this. Not to my knowledge. However, if you implement

Would be strange...

> it something like this: (the name and return type of course doesn't matter;
> just the way of specifying which files gets mmap).
> 
> ppfBool CacheFile(const char* pUrl)

Did you have a look at the mmap() doc I sent you?
Itīs not about caching files - it is about making it possible to access
files as parts of system memory, i.e. somehow like that:

int Handle = open ("myfile", <...>);
void *MyFileMap = mmap (0, TheFileSize, <some flags>, Handle, <some more
things>);
int FirstWord = ((int *) MyFileMap) [0]; // reads the first int from the
file
//...
close (Handle);

i.e. you can directly access the file as if it were some region in your
virtual memory. Well, in fact it *is*...

> btw, several of the errors was because members of classes that was const was
> being deleted, so you'll want to be aware of that too.

Thatīs more serious. Can you look again where exactly this was?

> >>surprised. That along with the fact that your compiler obviously doesn't
> >>consider this an error indicates to me that there's something weird going
> >>on here I don't know about...
> >
> >Perhaps it is intelligent enough to see that it doesn't matter
> >*in this case*...
> >
> It should ATLEAST give a warning, then. I don't see why a compiler should
> assist someone in writing incorrect code, even if it comes out the same.
> 
> char* pThisIsAString = "whatever";
> WriteToDisk(pThisIsAString);
> WriteToDisk(pThisIsaString);
> 
> Should this compile? I would consider it a bug if it did...

Why shouldnīt it? pThisIsAString is a completely valid C-style string.
And, depending on the implementation, you eventually *can* modify it.

> Reminds me of when Microsoft first said that each program would be given
> it's own memory, and other programs couldn't read or write to this memory in
> MS's new OS. But later, people found out something that was quite clearly a
> bug that allowed both reading and writing to other processes' memory. Do you
> know what Microsoft called it? a "feature" :)

Yup. I was quite surprised when I saw game trainers simply reading from
the gamesī memory...
But thatīs really a different problem that the const thing - in fact the
const thing IMHO really is no problem at all. Itīs perhaps a bit sloppy
written, but thatīs it.

> >Byte order. if you have some integer, say 123456789 (hex 75BCD15),
> >little-endian machines (like the x86) store it as 15CD5B07 (i.e. least
> >significant byte first) while big-endian machines (e.g. PPC) store it as
> >075BCD15 (most significant byte first). That sometimes makes reading binary
> >data portably a real hassle.
> >
> Sometimes you REALLY wonder why people couldn't just have agreed on this
> from the start, don't you? I mean, something as stupid as this DOESN'T

Well, which one would you have chosen? They are completely equal...

> >>had to delete the linux partitions and install linux again. It's working
> >>now, but it still can't mount the swapdrive... btw, how do you get to the
> >
> >Did you set up one?
> >
> Sure did, all 400 megs of it - I know that's way to large, but diskdruid

... and thatīs the problem. swap partitions may not be larger than 127M
(donīt ask me why).

> There's one thing I'm still wondering about, though; what about that using
> new and delete in C? Isn't that only C++? Shouldn't C files use malloc() and
> free() ?

Yep. Why?

> Also, in PenguinEvent, they are using classes all over in the function
> declaration lists and implementations. Here's an example:
> 
> // this would be a member of ppeBindingMap if we could have a C++ inteface
> ppBool ppeOpenBindingMap(ppeEventType type)
> {
>   ppeBindingMap *map = ppeBindingMap::binding_maps[type];
>   if(! map ) switch (type) {
>     case ppeUserEventType: map= new ppeUserBindingMap; break;
> 
>     default :   return true; /*Unknown type, spit the dummy*/
>   }
>   ppeBindingMap::binding_maps[type] = map;
> 
>   map->refcount++;
> 
>   return false;
> }
> 
> and yes, I checked: ppeBindingMap is a class, not a structure (besides, I
> don't think "::" is C anyway).
> 
> When you say everything low-level must be implemented in C, do you mean some

No. I said all lowlevel *APIs* have to be C. That doesnīt say anything
about how the stuff is *implemented*.


	Christian