shared arrray problem

Charles Hixson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 19 19:34:57 PST 2016



On 11/19/2016 05:52 PM, ag0aep6g via Digitalmars-d-learn wrote:
> On 11/20/2016 01:33 AM, Charles Hixson via Digitalmars-d-learn wrote:
>> Yes.  I was hoping someone would pop up with some syntax making the
>> array, but not its contents, const or immutable, which I couldn't figure
>> out how to do, and which is what I really hoped would be the answer, but
>> it appears that this isn't part of the syntax.
>
> Yup, head const is not part of the language. You'd have to find a 
> library solution or write something yourself.
>
>> I really *can't* allow the length to be
>> changed,
>
> Your emphasis suggests that user could break things for your code. 
> They can't. Any changes to the length will only affect the slice on 
> the user's end. They can only fool themselves. That may be bad enough 
> to warrant a more restricted return type, but for your code it's safe 
> to return a plain dynamic array.
Whether you would call the change "break things for your code" might be 
dubious.  It would be effectively broken, even if technically my code 
was doing the correct thing.  But my code wouldn't be storing the data 
that needed storing, so effectively it would be broken. "Write something 
for yourself" is what I'd like to do, given that the language doesn't 
have that built-in support, but I can't see how to do it.  I want to end 
up with a continuous array of ubytes of a given length with certain 
parts reserved to only be directly accessible to the defining class, and 
other parts accessible to the calling class(es).  And the length of the 
array isn't known until run time.  So I guess the only safe solution is 
to do an extra copy...which isn't a problem in this particular 
application as I only need to do it twice per file opening (once on 
opening, once on closing), but for other applications would be a real drag.


More information about the Digitalmars-d-learn mailing list