托管类型的SizeOf [英] SizeOf for managed types

查看:126
本文介绍了托管类型的SizeOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人知道如何获取托管类型的字节大小吗?


我有哈希表和我想要检查字节大小。我可以使用sizeof获得大小

的值类型与prmitives类型(如int32等)。


谢谢

- -

Salvador Alvarez Patuel

Exony Ltd - 英国伦敦

Hi,

Does anybody know how to get the size in bytes of a managed type?

I have a hashtable and I want to check the size in bytes. I can get the size
using sizeof for value types with prmitives types (like int32, etc).

Thanks
--
Salvador Alvarez Patuel
Exony Ltd - London, UK

推荐答案



" Salvador" <萨****** @ discussions.microsoft.com>在留言中写道

新闻:E2 ********************************** @ microsof t.com ...

"Salvador" <Sa******@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...


有人知道如何获得托管类型的字节大小吗?

我有一个哈希表,我想检查字节大小。我可以使用sizeof获得
大小的
值类型与prmitives类型(如int32等)。

谢谢

-
Salvador Alvarez Patuel
Exony Ltd - 英国伦敦
Hi,

Does anybody know how to get the size in bytes of a managed type?

I have a hashtable and I want to check the size in bytes. I can get the
size
using sizeof for value types with prmitives types (like int32, etc).

Thanks
--
Salvador Alvarez Patuel
Exony Ltd - London, UK




没有可靠的方法可以从
$ b中了解托管对象的大小$ b您的应用程序代码。

为什么您需要检查托管类型的大小?


Willy。



There is no reliable way to know the size of managed objects from within
your application code.
Why would you ever need to check the size of managed types?

Willy.


请参阅System.Runtime.InteropServices.Marshal.SizeOf()

" Salvador"写道:
See System.Runtime.InteropServices.Marshal.SizeOf()
"Salvador" wrote:


有人知道如何获得托管类型的字节大小吗?

我有一个哈希表,我想检查字节大小。我可以使用sizeof来获得大小
的值类型与prmitives类型(如int32等)。

谢谢

-
Salvador Alvarez Patuel
Exony有限公司 - 英国伦敦
Hi,

Does anybody know how to get the size in bytes of a managed type?

I have a hashtable and I want to check the size in bytes. I can get the size
using sizeof for value types with prmitives types (like int32, etc).

Thanks
--
Salvador Alvarez Patuel
Exony Ltd - London, UK



不,这将返回对象的大小,因为它将被封送并且可以

只能与值类型(struct)一起使用。


尝试这个...

struct Test

{

公共字符串s;

}


....

测试t =新测试( );

ts ="猜对象大小" ;;

Console.WriteLine(System.Runtime.InteropServices.M arshal.SizeOf(t));


结果是4,这绝对不是对象t的正确大小。


Willy。



" KH" < KH@discussions.microsoft.com>在消息中写道

news:74 ********************************** @ microsof t.com ...
No, this returns the size of the object as it would be marshaled and can
only be used with value types (struct).

try this...
struct Test
{
public string s;
}

....
Test t = new Test();
t.s = "guess the object size";
Console.WriteLine(System.Runtime.InteropServices.M arshal.SizeOf(t));

the result is 4, which in no way is the correct size of the object t.

Willy.


"KH" <KH@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
参见System.Runtime.InteropServices.Marshal.SizeOf()

" Salvador"写道:
See System.Runtime.InteropServices.Marshal.SizeOf()
"Salvador" wrote:


有人知道如何获得托管类型的字节大小吗?

我有一个哈希表,我想检查字节大小。我可以使用sizeof获得
大小的
值类型与prmitives类型(如int32等)。

谢谢

-
Salvador Alvarez Patuel
Exony Ltd - 英国伦敦
Hi,

Does anybody know how to get the size in bytes of a managed type?

I have a hashtable and I want to check the size in bytes. I can get the
size
using sizeof for value types with prmitives types (like int32, etc).

Thanks
--
Salvador Alvarez Patuel
Exony Ltd - London, UK



这篇关于托管类型的SizeOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆