通用类型的大小
有没有什么方法可以确定类似的内容的字节大小,
TItem <T> = record
Data : T;
end;
我可以写类似的内容
function TItem <T>.GetByteSize : Integer;
begin
if (T = String) then
Result := GetStringByteSize (Data as String)
else
Result := SizeOf (Data);
end;
或可能在专业化的帮助下吗?
function TItem <String>.GetByteSize : Integer;
begin
Result := GetStringByteSize (Data)
end;
function TItem <T>.GetByteSize : Integer;
begin
Result := SizeOf (Data);
end;
谢谢!
Is there any way to determine the size in bytes of something like
TItem <T> = record
Data : T;
end;
Can I write something like
function TItem <T>.GetByteSize : Integer;
begin
if (T = String) then
Result := GetStringByteSize (Data as String)
else
Result := SizeOf (Data);
end;
or perhaps with the help of specialization?
function TItem <String>.GetByteSize : Integer;
begin
Result := GetStringByteSize (Data)
end;
function TItem <T>.GetByteSize : Integer;
begin
Result := SizeOf (Data);
end;
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
获取实例化类型的大小是否有问题?
或者您可以像这样定义 GetByteSize:
Is there something wrong with taking the size of the instantiated type?
Or you could define GetByteSize like this:
不,据我所知,你不能根据类型进行专门化
No, you can't specialize depending on type as far as I know