Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 08, 2009 Can i safely cast void* from void[]? | ||||
---|---|---|---|---|
| ||||
Hi, I remember i read around the D site that dinamic arrays can be stored in system memory in a 'non contiguous' way (different locations). I was trying to find again that page but haven't had any lucky. I'm not crazy, i know i saw it. Anyway, i need this info to ensure that i can/can't cast from void[] to void*. I'm working with D dinamic arrays but i need to work this data then with windows API's, these functions take void* as parameters. I pass params of type cast(void*)void[] and have had no problems at the moment. But, what if data in the array is not stored contiguously? windows functions will crash right? I hope you get the idea, and i hope someone to answer me. Thanx. |
February 08, 2009 Re: Can i safely cast void* from void[]? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz | On Mon, 09 Feb 2009 00:25:41 +0300, Heinz <malagana15@yahoo.es> wrote: > Hi, > > I remember i read around the D site that dinamic arrays can be stored in system memory in a 'non contiguous' way (different locations). I was trying to find again that page but haven't had any lucky. I'm not crazy, i know i saw it. > Never heard that. > Anyway, i need this info to ensure that i can/can't cast from void[] to void*. I'm working with D dinamic arrays but i need to work this data then with windows API's, these functions take void* as parameters. I pass params of type cast(void*)void[] and have had no problems at the moment. But, what if data in the array is not stored contiguously? windows functions will crash right? > > I hope you get the idea, and i hope someone to answer me. Thanx. No need to cast: void[] array = ...; void* ptr = array.ptr; |
February 08, 2009 Re: Can i safely cast void* from void[]? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz | Heinz Wrote:
> I remember i read around the D site that dinamic arrays can be stored in system memory in a 'non contiguous' way (different locations). I was trying to find again that page but haven't had any lucky. I'm not crazy, i know i saw it.
It could have meant that arrays might be extended by allocating more pages onto the end as needed and as possible - the physical location of these pages would be non-contiguous, but they'd be contiguous in the memory view. Any other way would be replicating processor features in software, so I don't see it happening.
|
February 08, 2009 Re: Can i safely cast void* from void[]? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heinz | Heinz wrote:
> Hi,
>
> I remember i read around the D site that dinamic arrays can be stored in system memory in a 'non contiguous' way (different locations). I was trying to find again that page but haven't had any lucky. I'm not crazy, i know i saw it.
>
> Anyway, i need this info to ensure that i can/can't cast from void[] to void*. I'm working with D dinamic arrays but i need to work this data then with windows API's, these functions take void* as parameters. I pass params of type cast(void*)void[] and have had no problems at the moment. But, what if data in the array is not stored contiguously? windows functions will crash right?
>
> I hope you get the idea, and i hope someone to answer me. Thanx.
Dynamic arrays are guaranteed to be stored contiguously (possibly it was a suggestion?). Casting to void* should work fine, but to be more portable, you should use (cast(void*) arr.ptr) (in case in future versions or on different platforms, the ptr and length feilds are reversed)
|
Copyright © 1999-2021 by the D Language Foundation