Re: Can i get a array Slicing where the top from?and how?

2016-03-31 Thread Ali Çehreli via Digitalmars-d-learn

On 03/30/2016 11:39 PM, Dsby wrote:
> Like this:
>
> ubyte[] fun()
> {
>  ubyte[] str = cast(ubyte[])"hello world";
>  ubyte[] by = Mallocator.instance.allocate(str.length);
>  by[] = str[];
>  return by[5..$];
> }
>
> void mian()
> {
>  ubyte[] aa = fun();
> // i want free the aa's momeny.
> //Mallocator.instance.deallocate(aa);// it is erro, aa.ptr != by.ptr?
>   // can I get the by's ptr and length?
> }
>
>
> can I get "by" in main function by aa?
> i can get the way?is it possible ?

No, you can't.

Normally, you would have a cleanup function that corresponds to fun(), 
which the users call when they're done with their resources.


void foo_cleanup(ubyte[] by) {
// Do your magic here to find the original pointer.
// For example, you can use an AA to map from
// by.ptr to the original pointer.
}

Ali



Can i get a array Slicing where the top from?and how?

2016-03-31 Thread Dsby via Digitalmars-d-learn

Like this:

ubyte[] fun()
{
ubyte[] str = cast(ubyte[])"hello world";
ubyte[] by = Mallocator.instance.allocate(str.length);
by[] = str[];
return by[5..$];
}

void mian()
{
ubyte[] aa = fun();
   // i want free the aa's momeny.
   //Mallocator.instance.deallocate(aa);// it is erro, aa.ptr != 
by.ptr?

 // can I get the by's ptr and length?
}


can I get "by" in main function by aa?
i can get the way?is it possible ?