digitalmars.D.learn - Can i get a array Slicing where the top from?and how?
- Dsby (18/18) Mar 30 2016 Like this:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (10/27) Mar 31 2016 No, you can't.
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 ?
Mar 30 2016
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
Mar 31 2016