Re: [Re: [AD] New WIP]

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


In reply to George Foot (George Foot <gfoot@xxxxxxxxxx>):
>Casting away constness is very bad though -- the compiler can make 
>optimisations assuming the pointed-to data does not change, when in fact 
>you're altering it.  Acquiring the surface is changing the data pointed 
>to (several levels of indirection further down), so the function should 
>not take a const parameter.

Mark changeable data as `volatile' - this works as a poor man's
`mutable' C++ keyword. In essence, you are telling the compiler it can
never trust the contents of this keyword to be the same after any time
has elapsed (ie. the code a = sqrt(b); c = sqrt(b); may not give a,c
such that a == c).

And so the compiler does not make the assumption that this bit of data
will be constant.

>I can't think of any bitmap operations for which it *would* be 
>appropriate to have a const parameter.  Any drawing operation modifies 
>the content, and even reading operations may involve a bank switch.  
>That's true in all platforms, not just Windows.

When applying const, we do not figure out how it changes the hardware,
or whether some cache is changed, updated, etc. - simply this: if an
object has operations a and b what happens if we apply:

ab(object)
ba(object)

if ab(object) is the same as a(object) in all cases, then b's parameter
is const. Similarly, if ba(object) is the same as b(object) in all
cases, then a's parameter is const.

The const keyword isn't just the simple statement "compiler, I will not
change this object's data" - it is the statement "user, I will not
change your object's appearance or behaviour".

Reading from a bitmap does not change the function or the appearance of
the bitmap, so it should take a const parameter. Writing to a bitmap
changes its appearance, and so should not take a const parameter.

The issue of bitmap acquisition/release is more complicated. If
acquiring a bitmap is only necessary for writing to it, then it would be
fine to remove the const keyword. If it is necessary for reading from
it, then we should present the parameter as const.

The way around my earlier argument is "we are not change the bitmap's
behaviour, but the behaviour of the system that is accessing the bitmap"
:-)

Bye for now,
-- 
Laurence Withers, lwithers@xxxxxxxxxx
                http://www.lwithers.demon.co.uk/

Attachment: signature.asc
Description: PGP signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/