最大字符数组大小? [英] Maximum char array size?

查看:66
本文介绍了最大字符数组大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近注意到一些关于大内存块分配的线程(充满了声音和愤怒,表示没有任何内容)。我将开始个人宠物项目,我将使用memchr(),

memcmp(),memmove()。假设机器

有足够的内存,那么

字符数组的ANSI C大小是否保证成功? memxxx()函数是否可以使用

大小?我希望在内存块中有65792个字节(== 64K + 256,长故事,

不要问)。我可以少用,但程序

代码会变得笨拙。我可以忍受一些磁盘颠簸,但我显然不希望程序倾销核心。


我的主平台是linux + gcc 。我需要与

Windows 32位世界兼容,但不一定是古老的实模式DOS。如果

max size是特定于实现的,是否有一个标准变量,我可以在运行/编译时查找
?另外,与
malloc()相比有什么优势,而不是在编译时声明一个数组(除了需要

来定期声明中的数组维度) )?


-

Walter Dnes;我的电子邮件地址是* ALMOST *,如 wz*******@waltdnes.org

删除z得到我的真实地址。如果被阻止,请按照550消息末尾的说明进行操作。

I''ve noticed a few threads (full of sound and fury, signifying
nothing) here recently about allocation of large memory blocks. I''m
about to start on a personal pet project where I''ll be using memchr(),
memcmp(), memmove() a lot. Is there an ANSI C maximium size for
character arrays which are guaranteed to succeed, assuming the machine
has sufficient memory? And will the memxxx() functions work with that
size? I''m looking at hopefully 65792 bytes ( == 64K + 256, long story,
don''t ask) in a memory block. I could get by with less, but the program
code would be clunkier. I could put up with some disk-thrashing, but I
obviously don''t want the program dumping core.

My home platform is linux+gcc. I need to be compatable with the
Windows 32-bit world, but not necessarily ancient real-mode DOS. If the
max size is implementation-specific, is there a standard variable that I
can look up at run/compile time? Also, are there any advantages to
malloc(), versus declaring an array at compile time (other than the need
to macro-ize the array dimension in a regular declaration)?

--
Walter Dnes; my email address is *ALMOST* like wz*******@waltdnes.org
Delete the "z" to get my real address. If that gets blocked, follow
the instructions at the end of the 550 message.

推荐答案

2004年6月13日22格林威治标准时间17:53,在comp.lang.c中,Walter Dnes(删除''z''

来获取我的真实地址)" < WZ ******* @ waltdnes.org>写道:
On 13 Jun 2004 22:17:53 GMT, in comp.lang.c , "Walter Dnes (delete the ''z''
to get my real address)" <wz*******@waltdnes.org> wrote:
memcmp(),memmove()很多。假设机器有足够的内存,那么
字符数组的ANSI C大小是否保证成功?


标准(5.2.4.1)保证实现必须支持

- 字符串文字或宽字符串文字中的4095个字符

(连接后)

- 对象中的65535字节(仅限托管环境中)


memxxx()函数是否可以使用该大小?


无法保证任何一项功能都能成功,内存充足



如果
max size是特定于实现的,是否有一个标准变量,我可以在运行/编译时查找?


这是特定于实现的,并且我不知道要知道它。

此外,是否有任何优势
malloc(),而不是在编译时声明一个数组(除了需要在常规声明中宏关闭数组维度)?
memcmp(), memmove() a lot. Is there an ANSI C maximium size for
character arrays which are guaranteed to succeed, assuming the machine
has sufficient memory?
The standard (5.2.4.1) guarantees an implementation must support
- 4095 characters in a character string literal or wide string literal
(after concatenation)
- 65535 bytes in an object (in a hosted environment only)

And will the memxxx() functions work with that size?
There''s no guarantee that either function will succeed, memory sufficient
or not.
If the
max size is implementation-specific, is there a standard variable that I
can look up at run/compile time?
It is implementation-specific and thre''s no way I''m aware of to know it.
Also, are there any advantages to
malloc(), versus declaring an array at compile time (other than the need
to macro-ize the array dimension in a regular declaration)?




构建大小,自动内存中的占用空间更小(例如堆栈与堆),

可能更慢....

-

Mark McIntyre

CLC FAQ< http://www.eskimo.com/~scs/C-faq/top.html>

CLC自述文件:< http:/ /www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>

---- ==通过Newsfeed.Com发布 - 无限制 - 未经审查 - 安全Usenet新闻== ----
http://www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组

--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---

---- ==通过新闻发布.Com - Unlimited-Uncensored-Secure Usenet News == ----
http:// www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组

--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---



build size, lower footprint in automatic memory (eg stack vs heap),
possibly slower....
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


Walter Dnes (删除''z''来获取我的真实地址)写道:
Walter Dnes (delete the ''z'' to get my real address) wrote:
我注意到最近有关于分配的几个线程(充满了声音和愤怒,表示什么都没有)大内存块。我将开始个人宠物项目,我将使用memchr(),
memcmp(),memmove()。假设机器有足够的内存,那么
字符数组的ANSI C大小是否保证成功? memxxx()函数是否可以使用
大小?我希望在内存块中看到65792字节(== 64K + 256,长故事,不要问)。我可以少花钱,但程序代码会变得笨拙。我可以忍受一些磁盘颠簸,但我显然不希望程序转储核心。
I''ve noticed a few threads (full of sound and fury, signifying
nothing) here recently about allocation of large memory blocks. I''m
about to start on a personal pet project where I''ll be using memchr(),
memcmp(), memmove() a lot. Is there an ANSI C maximium size for
character arrays which are guaranteed to succeed, assuming the machine
has sufficient memory? And will the memxxx() functions work with that
size? I''m looking at hopefully 65792 bytes ( == 64K + 256, long story,
don''t ask) in a memory block. I could get by with less, but the program
code would be clunkier. I could put up with some disk-thrashing, but I
obviously don''t want the program dumping core.




由于C有指针,为什么呢你需要经常使用memmove()吗?

移动大块内存是浪费计算机资源。


在工作中,我在考虑写作一个优化的memcpy或memmove

函数,当我问自己时,我们永远不需要移动

大块内存,只需使用指针。但是,唉,有时必须将数据移开。为了分析。

-

Thomas Matthews


C ++新闻组欢迎辞:
http://www.slack.net/~shiva/welcome.txt

C ++常见问题: http://www.parashift .com / c ++ - faq-lite

C常见问题: http://www.eskimo.com/~scs/c-faq/top.html

alt.comp.lang.learn。 c-c ++ faq:
http:// www .raos.demon.uk / acllc -c ++ / faq.html

其他网站:
http://www.josuttis.com - C ++ STL图书馆书籍
http://www.sgi.com/tech/stl - 标准模板库comp.lang.ci中的



Since C has pointers, why do you need to use memmove() a lot?
Moving large blocks of memory is a waste of computer resources.

At work, I was thinking about writing an optimized memcpy or memmove
function, when I asked myself, "We should never be needed to move
big blocks of memory, just use a pointer." But alas, there are times
when one must move data "out of the way" in order to be analyzed.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library


读取:
字符数组是否有ANSI C最大值假设机器有足够的内存,保证成功吗?


在托管环境中标准要求至少有一个对象

65535字节可以创建,旧标准只要求32767

字节。看起来很低?标准并没有试图给所有

实施带来太多负担,因此翻译限制远低于某些系统能够提供的功能,例如, 64位服务器可以轻松容纳

对象,这些对象的大小为千兆字节,其中很多都是(所有这些都取决于

的存储空间和允许使用的时间) '慢''

东西),但有些微型计算机的所有

对象的使用量不能超过64k(是的,总计)。

memxxx()函数是否可以使用该大小?


mem *函数适用于任何可以成功创建的对象,无论是在编译还是运行时。

我希望在内存块中看到65792字节(== 64K + 256,长故事,不要问)。
我的主平台是linux + gcc。我需要与Windows 32位世界兼容,但不一定是古老的实模式DOS。


你还没有提到这些街区有多少所以很难说,但是在

一般你应该没那么大在这些机器上,如果使用malloc或

realloc,系统上通常可以免费使用的内存量为



如果max size是特定于实现的,是否有一个标准变量
我可以在运行/编译时查找?


。没有什么标准你可以参考 - 编译并运行

程序。 (有些事情你可以在你提到的两个平台上进行咨询,但它们彼此不同,并且不在c $ / $
标准之外。)

另外,与malloc()有什么好处,而不是在编译时声明一个数组


有些人更喜欢任何实际大小的对象分配的存储空间,并且确实有些系统预计它只会为自动对象提供有限的空间。第三个选项是使用静态持续时间存储,

,它可以像自动对象一样受限制。

(除了需要宏观化数组维度之外)在常规的
声明中)?
Is there an ANSI C maximium size for character arrays which are guaranteed
to succeed, assuming the machine has sufficient memory?
in a hosted environment the standard requires that at least one object
65535 bytes in size can be created, the older standard demanded only 32767
bytes. seem low? the standard doesn''t try to place too much burden on all
implementations, so the translation limits are far below what some systems
are capable of providing, e.g., a 64 bit server might easily accommodate
objects which are gigabytes in size and many of those (all depending on the
amount of money spent on storage and time allowed to make use of `slow''
stuff), but some microcomputers cannot have more than 64k in use for all
objects (yes, in total).
And will the memxxx() functions work with that size?
the mem* functions will work with any object which can be successfully
created, whether at compile or run time.
I''m looking at hopefully 65792 bytes ( == 64K + 256, long story,
don''t ask) in a memory block. My home platform is linux+gcc. I need to be compatable with the
Windows 32-bit world, but not necessarily ancient real-mode DOS.
you haven''t mentioned how many of those blocks so it''s hard to say, but in
general you should be fine with that size on those machines totalling up to
the amount of memory that is customarily free on the system if malloc or
realloc are used.
If the max size is implementation-specific, is there a standard variable
that I can look up at run/compile time?
it is. there is nothing standard you can consult -- compile and run the
program. (there are things you can consult on both the platforms you''ve
mentioned, but they are different from one another and outside of the c
standard.)
Also, are there any advantages to
malloc(), versus declaring an array at compile time
some people prefer objects of any real size to be of allocated storage, and
indeed some systems expect it so only provide a limited amount of space for
automatic objects. the third option is using static duration storage,
which can be just as limited as automatic objects, or not.
(other than the need to macro-ize the array dimension in a regular
declaration)?




做什么?如果你的意思是避免在你的程序中使用魔术常量,那么(通过使用宏代替),那么它同样适用于数组维度,因为它们对于malloc参数是



#define BUCKET_SIZE 65792

#define NUM_BUCKETS 1


char bucketarray [NUM_BUCKETS] [BUCKET_SIZE];

char * bucketmem = malloc(NUM_BUCKETS * BUCKET_SIZE); assert(0!= bucketmem);


使用当前标准的任何* BUCKET *标识符都可以是变量

而不是宏,尽管数组和malloc,但不是指针,

不能在文件范围内(必须在块范围内)。


-

a签名



do what? if you mean avoiding the use of `magic constants'' in your program
(by using macros instead), then that applies equally to array dimensions as
to malloc arguments.

#define BUCKET_SIZE 65792
#define NUM_BUCKETS 1

char bucketarray [NUM_BUCKETS] [BUCKET_SIZE];
char * bucketmem = malloc(NUM_BUCKETS * BUCKET_SIZE); assert(0!=bucketmem);

with the current standard any of the *BUCKET* identifiers can be variables
instead of macros, though the array and the malloc, but not the pointer,
cannot be at file scope (would have to be in a block scope).

--
a signature


这篇关于最大字符数组大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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