x64和BSTR分配,有什么变化? [英] x64 and BSTR allocation, what has changed?
问题描述
在win32模式下,BSTR的UINT长度为前缀,并且完全由
零字符终止。
因此,如果您分配了Hello World,那么这将分配28个字节。
在x64和(IA64也是如此)它将变成32个字节,因为
a指针,是8个字节而不是4个字节。
长度前缀-still-是UINT而不是UINT_PTR。
但似乎我'还不太完美。还有其他
信息或规则在win32 BSTR分配之上发生了变化吗?
谢谢!
>在win32模式下,BSTR的UINT长度为前缀,并且完全由零字符终止。
>所以,如果你分配了Hello World,这将分配28个字节。
在x64和(IA64)中,它将变为32个字节,因为指针是8个字节而不是4个字节。
你如何得出这个结论?指针在哪里进入?
BSTR?
Dave
David Lowndes <沓**** @ example.invalid>在消息中写道
新闻:6o ******************************** @ 4ax.com ...在win32模式下,BSTR的UINT长度为前缀,并且完全由
一个零焦点终止。
所以,如果你分配了Hello World,它将分配28个字节。
在x64和(IA64中)它将变为32个字节,因为
指针是8个字节而不是4个字节字节。
你是如何得出这个结论的?指针在哪里进入BSTR?
ok,
我会解释一下。
不是指针-itself-进入但是指针指向UINT长度
前缀。
在X64和IA64上,指针是-not-到UINT长度前缀,但是到
UINT_PTR长度前缀。
但是......但是,如果你想要长度,你需要一个UINT前缀,而不是一个
UINT_PTR前缀。
我不是说这个,只是犹豫。也许有人知道真实的事实...
BSTR __stdcall SysAllocString(const OLECHAR *输入)
{
PWSTR retval = NULL;
if(输入!= NULL)
{
UINT_PTR slen = lstrlenW(输入);
UINT_PTR newlen = slen * sizeof(OLECHAR)+ sizeof(UINT_PTR)+
sizeof(OLECHAR);
PWSTR temp = NULL;
temp =(PWSTR):: CoTaskMemAlloc(newlen);
if(temp!= NULL)
{
UINT * plen =(UINT *)temp;
plen [0] =(UINT)slen * sizeof(OLECHAR);
retval =& temp [sizeof( UINT_PTR)/ sizeof(OLECHAR)];
if(slen> 0)
CopyMemory(retval,input,(slen + 1)* sizeof(OLECHAR));
}
}
返回retval;
}
Dave
>>你是如何得出这个结论的?指针在哪里进入BSTR?
好的,
我会解释一下。
不是指针-itself-进入但是指针指向UINT长度
前缀。
在X64和IA64上,指针是-not-到UINT长度前缀,但是一个
UINT_PTR长度前缀。
所以,你说在64位平台上,BSTR有一个8字节
长度部分而不是4字节长度?如果它是
,我会感到惊讶。
我在MSDN文档中没有看到任何有关该假设的证据
或头文件。 SysStringLen定义为返回UINT而不是
UINT_PTR。
Dave
In win32 mode, a BSTR was UINT length prefixed and terminated exactly by a
zero char.
So if you allocated "Hello World" that would allocate 28 bytes.
In x64 and (IA64 as well) it would become 32 bytes, because of the fact that
a pointer, is 8 bytes instead of 4 bytes.
The length prefix -still- is a UINT however and not a UINT_PTR.
But it seems that I''m still not quite complete on par. Is there any other
info or rules that have changed on top off the win32 BSTR allocations?
Thanks!
>In win32 mode, a BSTR was UINT length prefixed and terminated exactly by azero char.
So if you allocated "Hello World" that would allocate 28 bytes.
In x64 and (IA64 as well) it would become 32 bytes, because of the fact that
a pointer, is 8 bytes instead of 4 bytes.
How do you come to that conclusion? Where does a pointer come into a
BSTR?
Dave
"David Lowndes" <Da****@example.invalid> wrote in message
news:6o********************************@4ax.com...In win32 mode, a BSTR was UINT length prefixed and terminated exactly by
a
zero char.
So if you allocated "Hello World" that would allocate 28 bytes.
In x64 and (IA64 as well) it would become 32 bytes, because of the fact
that
a pointer, is 8 bytes instead of 4 bytes.
How do you come to that conclusion? Where does a pointer come into a
BSTR?
ok,
I''ll explain this.
Not the pointer -itself- comes into but the pointer is to the UINT length
prefix.
On X64 and IA64, the pointer is -not- to the UINT length prefix, but to a
UINT_PTR length prefix.
But but... however, if you want the length, you need a UINT prefix, not a
UINT_PTR prefix.
I''m not stating this, just hesitating. Maybe someone knows the real facts...
BSTR __stdcall SysAllocString(const OLECHAR * input)
{
PWSTR retval = NULL;
if (input != NULL)
{
UINT_PTR slen = lstrlenW(input);
UINT_PTR newlen = slen * sizeof(OLECHAR)+ sizeof(UINT_PTR) +
sizeof(OLECHAR);
PWSTR temp = NULL;
temp = (PWSTR)::CoTaskMemAlloc(newlen);
if (temp != NULL)
{
UINT* plen = (UINT*)temp;
plen[0] = (UINT)slen * sizeof(OLECHAR);
retval = &temp[sizeof(UINT_PTR) / sizeof(OLECHAR)];
if (slen > 0)
CopyMemory(retval, input, (slen + 1) * sizeof(OLECHAR));
}
}
return retval;
}
Dave
>> How do you come to that conclusion? Where does a pointer come into aBSTR?
ok,
I''ll explain this.
Not the pointer -itself- comes into but the pointer is to the UINT length
prefix.
On X64 and IA64, the pointer is -not- to the UINT length prefix, but to a
UINT_PTR length prefix.
So, you''re saying that on 64-bit platforms, a BSTR has an 8 byte
length portion rather than a 4 byte length? I''d be surprised if it
was.
I don''t see any evidence for that assumption in the MSDN documentation
or the header files. SysStringLen is defined to return an UINT not
UINT_PTR.
Dave
这篇关于x64和BSTR分配,有什么变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!