English 中文(简体)
哪一种需要更多的记忆、说明价值或长期价值?
原标题:Which takes more memory, string value or long value?

我的客户申请与全球合作框架服务连接,我从服务器获得文件尺寸,作为<代码>long。 然后,我将其在客户中的数值改为string。 ∗∗∗∗∗∗∗∗

The application gets too many files sizes every time user changes the current directory path.

www.un.org/chinese/ecosoc 如果我把数值转换为string form from the WCF Service app 然后作为<条码>将其退回客户。 或者,我只是将体积作为<条码>长期值,让客户将其转换成<条码>,<> 格式

In other way which value take more bytes in the memory:

long size = 55050240;
string size = "52.5 MB"; 

long large_size = 56371445760;
string large_size = "52.5 GB";

UPDATE:

我使用这种方法将长期价值转换为一种扼制格式:

private string ConvertUnit(long source)
    {
        const int byteConversion = 1024;
        double bytes = Convert.ToDouble(source);

        if (bytes >= Math.Pow(byteConversion, 3)) //GB Range
        {
            return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 3), 2), " GB");
        }
        else if (bytes >= Math.Pow(byteConversion, 2)) //MB Range
        {
            return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 2), 2), " MB");
        }
        else if (bytes >= byteConversion) //KB Range
        {
            return string.Concat(Math.Round(bytes / byteConversion, 2), " KB");
        }
        else //Bytes
        {
            return string.Concat(bytes, " Bytes");
        }
    }

www.un.org/spanish/ecosoc 简短问题: 需要更多的记忆<代码> 价值或long值?

最佳回答

Having a service layer that output values that are formatted is a very bad idea. What happens if the requirements change and rather than a GB suffix, the client application UI needs to output in bytes? e.g. 56,371,445,760 ? This will required the client application to parse then re-format the data sent by the server.

此外,确定储存个人变数所需的记忆也很容易。 并非易事的是,要消除对你应用的总体影响。 你们的法典将不同处理不同类型的问题,因此,较小的变量可能会增加成本。

问题回答

“记忆、显示价值或长期价值”

C#中的规定为:统法协会编码特征(性质为两条)+该地址的协调人(最低4条,8条,按x64 .NET应用)。

长度为8英寸。 一旦超过x86的2个特性,或X64的任何特性,你就记忆犹新。

如果你重新发送大量相同规模的档案,扼杀最终会减少记忆。

对于你的实际问题,你应该用很长的时间来真正代表基本目标。

Edit: Corrected to take into account pointer size for string.

A NET string是一系列UTF-16代码单位,每个单位长2个。 因此,“52.5兆赫”将使用7*2=14英特,甚至无视根据程序“参数”和长处等附属领域提及方(4或8条)。 <long is 8 bytes, so it is clear the string is Much "fatter.

另外,你的例子没有传递同样的信息(你在扼杀中散布“割礼”,因此,我们喜欢比较 app和 or。

Even encoded in SOAP messages, long should be more compact than string.

由于所有这些原因,我只读long





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签