本文介绍了批处理文件中可以使用多少个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对批处理文件中可以设置多少个变量有些好奇.

I am a little curious about how many variable I can set in Batch File.

我在这里有一个小脚本

@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /L %%P IN (1,1,2147483647) DO (
    SET Foo[%%P]=%%P
    ECHO !Foo[%%P]!
)

但是此脚本将永远运行.那么,有什么办法可以找出可变数量限制?(当然,批处理文件中可以使用多少个变量.)

But this script would take forever to run. So, is there any way to find out variable amount limit?(and of course how many variable can be used in Batch file.)

由于下面的评论说var.金额可能因操作系统不同而有所差异.因此,如果您愿意回答,请使用Windows 7 64bit w/ 4 GB RAM作为指导.

Since comment below says that var. Amount may vary due to different OS. So if you would answer, use Windows 7 64bit w/ 4 GB RAM as your guideline.

任何帮助将不胜感激!

推荐答案

真正的答案是,它取决于计算机的限制,例如RAM,尤其是硬盘空间等等.但是,我可以确定您正在寻找的是理论答案,而不是实际的答案(我也是!).

Well the real answer is that it depends on the limitations of your machine such as RAM, especially hard disk space, and so forth. But, I am fairly certain you are looking for the theoretical answer, not the practical answer (I would be too!).

因此,对于理论上的答案,让我们在此假设以下内容(抱歉,如果我听起来很讽刺,但这是真实的要求,实际上不太可行):

So, for the theoretical answer, let's assume here the following (sorry if I sound sarcastic, but these are the real requirements and they're not so realistically possible):

  • 您的计算机体系结构是64位(最好是Itanium类).
  • 您有一个具有NTFS的128 TB硬盘
  • 您拥有精简的32核4THz(太赫兹)处理器,因此您可以在年老的日子之前看到它已经完成.
  • 您至少有至少384GB的RAM(如果您压缩名称并将空字符串用作值)
  • 只有65807文件最初是带有sp1的Windows 7 Professional附带的,再加上硬盘上的1个批处理文件.
  • 只有96783注册表最初在硬盘上带有sp1的Windows 7 Professional附带的索引.
  • Your computers architecture is 64-bit (preferably Itanium class).
  • You have a 128 TB hard drive with NTFS
  • You have a streamlined 32 core 4THz (terahertz) processor so you can see it complete before the day you die of old age.
  • You have at least and at least 384GB of RAM (if you compressed the names and used empty strings as values)
  • There are only the 65807 files that initially come with windows 7 professional with sp1 plus your 1 batch file on your hard disk.
  • There are only the 96783 registry indexes that initially come with windows 7 professional with sp1 on your hard disk.

因此,我们遇到的最大限制是如何存储批处理变量.使用带符号的int数组对它们进行寻址.这样最多可以将2,147,483,647个变量存储在内存中.现在,了解硬盘的作用所在.如果允许将硬盘用作批处理变量,则需要2个批处理变量才能将硬盘文件用作批处理变量:一个用于缓存,一个在for循环中.而且,现在我们可以使用4,294,967,295个额外的批处理变量.现在,对于注册表,假设Windows使用带符号的整数对注册表进行索引,则总共可以有2,147,483,647个注册表索引.现在,总和为(2,147,483,647-2)+(4,294,967,295-(65807 + 1))+(2,147,483,647-96783)=

So, the big limiter we encounter is how the batch variables are stored. They are addressed in an array using signed ints. This allows for a maximum of 2,147,483,647 variables stored in the memory. Now, for where the hard disk comes into play. If you would allow the hard disk to be used for batch variables, then you will need 2 batch variables to use the hard disk files as batch variables: one variable for the cache, and one in the for loop. And, now we have 4,294,967,295 extra batch variables that can be utilized. Now for the registry, assuming windows uses signed integers to index the registry, that would allow there to be a total of 2,147,483,647 registry indexes. Now, to total it all up, (2,147,483,647 - 2) + (4,294,967,295 - (65807+1)) + (2,147,483,647 - 96783) =

这篇关于批处理文件中可以使用多少个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:47