last day (15 days later) » 

6:48 PM
2
Q: Why mapped_file::data returns char* instead of void*

baolOr even better a template <T*>? In case the memory mapped file contains a sequence of 32 bit integers, if data() returned a void*, we could be able to static cast to std::uint32_t directly. Why did boost authors choose to return a char* instead? EDIT: as pointed out, in case portability is an ...

 
void is nothing. It's useless to dereference it. Mmaps aren't designed to be useless
 
@sehe: void would just mean: "I don't know what I'm pointing to, please make sure that you do before accessing the data!". It would make more sense to me than being certain that it is pointing to bytes even if it is indeed pointing to little endian 32 bit integers!
 
The point is that the mapped file does know. It points to bytes
 
@sehe: No, it points to what I wrote into the file.
 
@baol it points to bytes and only bytes. You should read Lightness' one more time
 
6:48 PM
@sehe: there are useful use cases in which the translation can be safely omitted.
@sehe: and even in cases in which the translation is needed it may be more useful to see the file as a stream of little endian 32 bits integers than just bytes! It's a matter of using the correct abstraction.
 
@baol So, in the end you don't really ask a question here. You just wanted to rant about how you think it's ridiculous that maps map regions of char data in memory. That that's not "using the correct abstraction" (ugh). Maybe start a blog. (If you don't want to hear other people's arguments, be sure to lock the comments.)
If you are still interested look through my answers for ideas on how to use mapped/shared memory with the proper abstractions.
 
I am asking why, and I do not get any valid answer.
Except people saying that the memory of an elaborator is organized in bytes and not in words
 
Since it is clearly subjective (people don't give "wrong" answers just to annoy you), why don't you just accept the fact that your views differ from those of others?
 
that, iirc, by definition is not true
I might
 
:D Cheers
 
6:49 PM
But I was trying to argument
with data and examples
 
SO is not the site for that
 
Agree
this is why I argumented and augmented the question
 
To be honest, I hear your argument about "abstraction"; I think that e.g. Boost Interprocess would make you more than happy
 
anyway
thanks for your time
next time
 
Anytime. Cheers again
 
6:51 PM
in the spirit of SO
don't start with "void is nothing. It's useless to dereference it. Mmaps aren't designed to be useless"
cheers
 
I tend to do that to nudge people into a realization.
You can, of course, still disagree. But at least you'll have pondered the flip side for a moment
 
Actually
I would be very interested in an answer
I cannot do a reinterpret cast in my code
due to constraints
and I really would like to know why force a reinterpret cast when a static cast would suffice
I may report a bug to boost, if there is no real reason
(and it seems there is not, given the answers)
 
FWIW the difference between static_cast to/from void* would be non-existent.
 
in practice ok
 
In theory even
 
6:56 PM
but reinterpret cast has a weird specification
 
@baol It's most definitely not a bug. It might be a design choice that doesn't convene you but that doesn't change a thing.
You could always just use mmap directly
 
nice to see it uses void :)
 
@baol Which is precisely why it is better to explicitly reinterpret rather than paper over your type punning with void*
Note that you're literally reinterpreting a region of memory. Might as well call it what it is.
@baol Yesh. Problem solved!
 
If I understand the specs correctly the reinterpret_cast is not guaranteed to do anything useful in this case (even if the spec specify that the behaviour should be "not surprising")
That area of memory is not "re-interpreted"
I understand it's phylosofical
but a memory mapped file is a pointer to some memory
made of what I put into before
not of bytes
there is nothing to re- interpret
anyway
we learn something every day
 
7:35 PM
(not all of us, anyway)
 
@baol Reinterpreting to char* and back (to the same cv-type) is specified as legal. This is the important bit.
Of course whatever you interpret to /something else/ is implementation defined at best, and frequently undefined
@baol you also put it in as bytes (or you did so through a pointer or reference that had already... you guessed it reinterpreted the area as a specific type)
954
Q: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?

e.JamesWhat are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast C-style cast (type)value Function-style cast type(value) and how does one decide which one to use in a specific case?

 
8:01 PM
so you really believe that a file is made of bytes and only bytes? :)
anyway, a memory mapped file is a pointer to some memory
thanks for the pointer
 

last day (15 days later) »