converting D's string to use with C API with unicode

Jack jckj33 at gmail.com
Sun Dec 6 20:54:43 UTC 2020


On Sunday, 6 December 2020 at 05:04:35 UTC, tsbockman wrote:
> On Sunday, 6 December 2020 at 02:07:10 UTC, Jack wrote:
>> On Saturday, 5 December 2020 at 23:31:31 UTC, tsbockman wrote:
>>> On Saturday, 5 December 2020 at 21:55:13 UTC, Jack wrote:
>>>>>     [...]
>>>
>>> `ws.length` is the length in `wchar`s, but `memcpy` expects 
>>> the size in bytes. (This is because it takes `void*` pointers 
>>> as inputs, and so does not know the element type or its size.)
>>
>> How do I get this size in bytes from wstring?
>
> `ws.length * wchar.sizeof` should do it. `wstring` is just an 
> alias for `immutable(wchar[])`, and the `length` property is 
> the number of `wchar` elements in the slice.

makes sense, thanks! solved the memory corruption


More information about the Digitalmars-d-learn mailing list