ARRAYS DOUBTS [英] ARRAYS DOUBTS

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

问题描述

1.

如果在编程时间内数组的大小未知,那么

如何声明这样的数组?


假设有一个名为arrClashname的数组(开头大小未知),


现在发生冲突时我想将该名称存储到

arrClashname ,

Therez一个while循环里面有一些条件,当碰撞发生并且一个名为Clash的变量设置为true并且它的
$ b $时判定
b名称必须添加到arrClashtime.I还有一个变量,它持有

冲突次数(inumberclashes),这会增加evry time

冲突发生。


因为我不知道循环内可能发生多少次碰撞我不能

定义静态arrClash名。


这样就可以了: -


Dim arrClashname(0)

arrClashname(0)="开始"


同时(某些条件)

.....

。 ....(某些条件可能会使Clash成立)

.....

如果(Clash = true)那么

inumberofclashes = inumberofclashes + 1

ReDim保留arrClashname(inumberofclashes)

arrClashes(inumberofclashes)= clashname

Endif

。 ....

.....

循环


这是正确的做法吗???或者还有其他方法吗?

Q2

如何为使用ARRAY创建的数组添加更多元素()

函数??


假设

Dim arrhit

arrhit = ARRAY(" start"," dfd")

现在我该如何向这个数组中添加更多元素?

arrhit [1] =" ssdfdf"直接或首先使用redim来增加大小和

然后添加新数据??


Q3

数组是否可以保存元素多个数据类型?如果是,在这种情况下如何完成

内存分配?存储在一起的元素是否具有相似的

数据类型?

假设整数数组现在如果数组从1000开始,因为整数

所以第二个元素将位于1002的第三位置1002并且很容易获得
fetch.But如果它可以保存任何数据类型的元素,它如何知道

应该获取多少字节一个元素可以是任何

数据类型

1.
If The size of the array is unknown during programming time then how is
such array declared??

Suppose there is an Array named arrClashname(size unknown at start),

Now when the clash occurs I want to store that name into the
arrClashname,
Therez a do while loop inside which has some conditions which decied
when clash occurs and a variable named Clash is set to true and its
name has to be added to arrClashtime.I also have a variable which hold
number of clashes (inumberclashes)which gets incremented evry time
clash occurs.

Since I don''t know how many clashes may occur inside the loop I cannot
define a static arrClashname.

This way can it be done:-

Dim arrClashname(0)

arrClashname(0)="Start"

Do while(some condition)
.....
.....(some conditions which may make Clash true)
.....
If (Clash = true) then
inumberofclashes=inumberofclashes+1
ReDim Preserve arrClashname(inumberofclashes)
arrClashes(inumberofclashes) = clashname
Endif
.....
.....
Loop

Is this the right way of doing??? Or there is some other way?
Q2
How can I add more elements to an array created using ARRAY()
function??

Suppose
Dim arrhit
arrhit=ARRAY("start","dfd")
Now how can I add more elements to this array??
arrhit[1]="ssdfdf" directly or use redim first to increase the size and
then add new data??

Q3
Can an array hold elements of more than one datatype? If yes how is the
memory allocation done in this case?? are the elements with similar
datatypes stored together??
suppose array of integers so now if array starts at 1000 since integers
so second element will be at location 1002 third at 1004 and so easy to
fetch.But if it can hold elements of any datatype how does it know that
how many bytes should be fetched for a element which can be of any
datatype??

推荐答案

divya 2006年9月27日写道04:08:03 -0700:
divya wrote on 27 Sep 2006 04:08:03 -0700:

1.

如果在编程时间内数组的大小未知,那么怎么样? />
这样的数组声明??


假设有一个名为arrClashname的数组(开始时大小未知),


现在当碰撞发生时我想把这个名字存入

arrClashname,

Therez一个while循环里面有一些条件决定了

当发生冲突时,av ariable命名为Clash设置为true并且其

名称必须添加到arrClashtime.I还有一个变量,其中包含

冲突次数(inumberclashes),这些变量会逐渐增加时间

冲突发生。


因为我不知道循环内可能发生多少冲突我不能定义
定义一个静态的arrClashname。


这样就可以了: -


Dim arrClashname(0)


arrClashname(0)="开始"


一边做(有些情况)

....

....(某些条件可能使Clash成立)

....

如果(Clash = true)那么

inumberofclashes = inumberofclashes + 1

ReDim Preserve arrClashname(inumberofclashes)

arrClashes(inumberofclashes)= clashname

Endif

.. ..

....

循环


这是正确的做法吗???还是有其他方式?
1.
If The size of the array is unknown during programming time then how is
such array declared??

Suppose there is an Array named arrClashname(size unknown at start),

Now when the clash occurs I want to store that name into the
arrClashname,
Therez a do while loop inside which has some conditions which decied
when clash occurs and a variable named Clash is set to true and its
name has to be added to arrClashtime.I also have a variable which hold
number of clashes (inumberclashes)which gets incremented evry time
clash occurs.

Since I don''t know how many clashes may occur inside the loop I cannot
define a static arrClashname.

This way can it be done:-

Dim arrClashname(0)

arrClashname(0)="Start"

Do while(some condition)
....
....(some conditions which may make Clash true)
....
If (Clash = true) then
inumberofclashes=inumberofclashes+1
ReDim Preserve arrClashname(inumberofclashes)
arrClashes(inumberofclashes) = clashname
Endif
....
....
Loop

Is this the right way of doing??? Or there is some other way?



Dim arrClashname()

Redim arrClashname(1)

arrClashname(0)=" Start"


然后像以前那样做其余的工作。

Dim arrClashname()
Redim arrClashname(1)
arrClashname(0) = "Start"

Then do the rest as before.


Q2

怎么能我为使用ARRAY创建的数组添加了更多元素()

函数??


假设

Dim arrhit

arrhit = ARRAY(" start"," dfd")

现在如何向此数组添加更多元素?

arrhit [1] = QUOT; ssdfdf"直接或首先使用redim来增加大小和

然后添加新数据?
Q2
How can I add more elements to an array created using ARRAY()
function??

Suppose
Dim arrhit
arrhit=ARRAY("start","dfd")
Now how can I add more elements to this array??
arrhit[1]="ssdfdf" directly or use redim first to increase the size and
then add new data??



我会redim然后循环添加新的数组项。不确定是否有一个内置于ASP的

数组加入函数。

I''d redim and then loop to add the new array items. Not sure if there''s an
array joining function built into ASP.


Q3

可以数组保存多个数据类型的元素?如果是,在这种情况下如何完成

内存分配?存储在一起的元素是否具有相似的

数据类型?

假设整数数组现在如果数组从1000开始,因为整数

所以第二个元素将位于1002的第三位置1002并且很容易获得
fetch.But如果它可以保存任何数据类型的元素,它如何知道

应该获取多少字节对于一个可以是任何

数据类型的元素?
Q3
Can an array hold elements of more than one datatype? If yes how is the
memory allocation done in this case?? are the elements with similar
datatypes stored together??
suppose array of integers so now if array starts at 1000 since integers
so second element will be at location 1002 third at 1004 and so easy to
fetch.But if it can hold elements of any datatype how does it know that
how many bytes should be fetched for a element which can be of any
datatype??



每个数组元素都是变体数据类型 - 我认为内存中的每个项目

都包含它的数据长度。


Dan

Each array element is a variant data type - I think each item in memory
includes it''s data length.

Dan




" divya" < di ********* @ yahoo.com写了留言

新闻:11 ********************* *@i3g2000cwc.googlegro ups.com ...

"divya" <di*********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...

1.

如果在编程时间内数组的大小未知,那么如何

这样的数组声明??


这种方式可以做到: -


Dim arrClashname(0 )


arrClashname(0)="开始"


做的时候(有些情况)

.. ..

....(某些条件可能会使Clash成立)

....

如果(Clash = true)那么

inumberofclashes = inumberofclashes + 1

ReDim Preserve arrClashname(inumberofclashes)

arrClashes(inumberofclashes)= clashname

Endif

....

....

循环


这是正确的方法做???
1.
If The size of the array is unknown during programming time then how is
such array declared??
This way can it be done:-

Dim arrClashname(0)

arrClashname(0)="Start"

Do while(some condition)
....
....(some conditions which may make Clash true)
....
If (Clash = true) then
inumberofclashes=inumberofclashes+1
ReDim Preserve arrClashname(inumberofclashes)
arrClashes(inumberofclashes) = clashname
Endif
....
....
Loop

Is this the right way of doing???



您是否试过它以查看是否产生错误?


Dim arrClashname()

Redim arrClashname(0)

做的事情

如果发生冲突然后

Redim保留arrClashname(UBound(arrClassName,1)+ 1)

arrClashname(UBound(arrClashname,1))= clashname

结束如果

循环

Have you tried that to see if it produces an error?

Dim arrClashname()
Redim arrClashname(0)
Do While something
If Clash Then
Redim Preserve arrClashname(UBound(arrClassName, 1) + 1)
arrClashname(UBound(arrClashname,1)) = clashname
End If
Loop


Q3

数组是否可以包含多种数据类型的元素?
Q3
Can an array hold elements of more than one datatype?



你试过吗?


Dim i

Dim a(2)

a(0)= CLng(393)

a(1)= CByte(1.290812)

a(2)=#2006-09-27#


对于i = 0到UBound(a,1)

Response.Write a(i)& "< hr />"

下一页

Have you tried it?

Dim i
Dim a(2)
a(0) = CLng(393)
a(1) = CByte(1.290812)
a(2) = #2006-09-27#

For i = 0 To UBound(a, 1)
Response.Write a(i) & "<hr />"
Next


如果是,

内存分配怎么样?在这种情况下完成?存储在一起的元素是否具有相似的

数据类型?

假设整数数组现在如果数组从1000开始,因为整数

所以第二个元素将位于1002的第三位置1002并且很容易获得
fetch.But如果它可以保存任何数据类型的元素,它如何知道

应该获取多少字节对于一个可以是任何

数据类型的元素?
If yes how is the
memory allocation done in this case?? are the elements with similar
datatypes stored together??
suppose array of integers so now if array starts at 1000 since integers
so second element will be at location 1002 third at 1004 and so easy to
fetch.But if it can hold elements of any datatype how does it know that
how many bytes should be fetched for a element which can be of any
datatype??



你在这里使用VB脚本,所以它不是真正合适的环境

如果你工作的话我关注这些事情,我会说!


雷在工作

You''re working with VB Script here, so it''s not really the right environment
to work in if you''re concerned with such things, I''d say!

Ray at work




divya < di ********* @ yahoo.com写了留言

新闻:11 ********************* *@i3g2000cwc.googlegro ups.com ...

"divya" <di*********@yahoo.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...

1.

如果在编程时间内数组的大小未知,那么如何是
这样的数组声明??


假设有一个名为arrClashname的数组(开始时大小未知),


现在发生冲突时我想把这个名字存入

arrClashname,

Therez一个while循环里面有一些条件决定了

发生碰撞时,名为Clash的变量设置为true,并且其

名称必须添加到arrClashtime.I还有一个变量,其中包含

冲突(inumberclashes)增加了逐渐的时间

冲突发生。


因为我不知道循环内可能发生多少冲突我不能

定义一个静态的arrClashname。


可以这样做: -


Dim arrClashname(0)

arrClashname(0)=" Start"


Do while(一些条件)

....

....(某些条件可能会让Clash成为真的)

....

如果(Clash = true)那么

inumberofclashes = inumberofclashes + 1

ReDim Preserve arrClashname(inumberofclashes)

arrClashes( inumberofclashes)= clashname

Endif

....

....

循环


这是正确的做法吗???还是有其他方式?
1.
If The size of the array is unknown during programming time then how is
such array declared??

Suppose there is an Array named arrClashname(size unknown at start),

Now when the clash occurs I want to store that name into the
arrClashname,
Therez a do while loop inside which has some conditions which decied
when clash occurs and a variable named Clash is set to true and its
name has to be added to arrClashtime.I also have a variable which hold
number of clashes (inumberclashes)which gets incremented evry time
clash occurs.

Since I don''t know how many clashes may occur inside the loop I cannot
define a static arrClashname.

This way can it be done:-

Dim arrClashname(0)

arrClashname(0)="Start"

Do while(some condition)
....
....(some conditions which may make Clash true)
....
If (Clash = true) then
inumberofclashes=inumberofclashes+1
ReDim Preserve arrClashname(inumberofclashes)
arrClashes(inumberofclashes) = clashname
Endif
....
....
Loop

Is this the right way of doing??? Or there is some other way?



这个问题有三种方法各有利弊: -


i)

Dim arr()

昏暗计数:count = 0


如果i = 0到x

如果条件然后

ReDim保留arr(计数)

arr(count)= fn(x)

count = count + 1

结束如果

下一页


优势这是非常简单的。

这种方法的问题是它不是保证每次扩展数组所需的内存分配

(需要连续的内存)可以通过扩展现有的分配来生成(事实上它

甚至可能不是内部使用的优化),这可能导致在阵列扩展时内存的许多分配/释放。更多

通常条件是真的,这个问题越严重。您还需要小心使用生成的arr的代码,以防万一它永远不会被创建

(因为条件永远不会是真的)这可以减轻能够测试

的数量= 0.

ii)


Dim arr()

昏暗计数:计数= 0


ReDim arr(x)


对于i = 0到x

如果条件然后

arr(count)= fn(x)

count = count + 1

结束如果

下一页


如果计数为0则

ReDim Preserve arr(count-1)

否则

擦除arr

结束如果


这种方法根本不会受到多个内存的影响

分配/解除分配问题。如果count明显小于x那么

我们最初分配的数组比我们需要的大。随着计数接近x

,这种方法非常有效。一个变化可能是不打扰

末尾的Truncatiing Redim,并且在访问数组时只需使用count - 1作为上限


< br $>
iii)


Const chunkSize = 100

Dim arr()

Dim count:count = 0

ReDim arr(chunkSize)


对于i = 0到x

如果条件那么

如果计数UBound(arr)ReDim Preserve arr(count + chunkSize)

arr(count)= fn(x)

count = count + 1

结束如果

下一页


如果计数0那么

ReDim保留arr(计数-1)

Else

擦除arr

结束如果


这种方法是上述两种方法的混合体。潜在内存的数量

分配/解除分配限制为第一个

方法的100倍,但结果数组的起始大小很小。我喜欢在类中隐藏这些东西的变体

是从一个

16元素数组开始,每次需要扩展时加倍。 br />

我使用的另一个修改是始终有一个元素0仍然未使用
。第一个真正的元素是1.这稍微简化代码(没有

需要担心UBound(arr)将错误不需要最终的If ... Erase

上面的业务。


There are three approaches to this problem each having pros and cons:-

i)

Dim arr()
Dim count : count = 0

For i = 0 to x
If condition Then
ReDim Preserve arr(count)
arr(count) = fn(x)
count = count + 1
End If
Next

Advantage this has is its very simple.
Problems with this approach is its not guaranteed that the memory allocation
needed to extend the the array each time (which needs to be in contiguous
memory) can be generated by extending the existing allocation (in fact it
may not even be an optimisation used internally), this could result in many
allocations/deallocations of memory as the array gets extended. The more
often condition is true the worse this problem gets. You''d also need to be
careful with code that uses the resulting arr in case it never got created
(because condition was never true) this is mitigated by being able to test
for count = 0.
ii)

Dim arr()
Dim count : count = 0

ReDim arr(x)

For i = 0 to x
If condition Then
arr(count) = fn(x)
count = count + 1
End If
Next

If count 0 then
ReDim Preserve arr(count-1)
Else
Erase arr
End If

This approach doesn''t suffer at all with multiple memory
allocation/deallocation issues. If count is significantly less than x then
we initially allocated a larger array than we need. As count approaches x
this approach is very effecient. One variation might be not to bother with
the truncatiing Redim at the end and just use count - 1 as the upper bound
when accessing the array.

iii)

Const chunkSize = 100
Dim arr()
Dim count : count = 0

ReDim arr(chunkSize)

For i = 0 to x
If condition Then
If count UBound(arr) ReDim Preserve arr(count + chunkSize)
arr(count) = fn(x)
count = count + 1
End If
Next

If Count 0 Then
ReDim Preserve arr(count-1)
Else
Erase arr
End If

This approach is a hybrid of the two above. The number of potential memory
allocations/deallocations are limited to 100th of what they are in the first
approach yet the starting size of the resulting array is small. A variation
that I prefer when hiding this cort of stuff in a class is to start with a
16 element array and double it each time it needs to be extended.

One other modification I use is to always have an element 0 which remains
unused. The first real element is at 1. This simplfies code somewhat (no
need to worry the UBound(arr) will error not need for the final If ... Erase
business above).


Q2

如何为使用ARRAY()创建的数组添加更多元素
函数??


假设

Dim arrhit

arrhit = ARRAY(" start"," dfd")

现在我该如何向这个数组中添加更多元素?

arrhit [1] =" ssdfdf"直接或首先使用redim来增加大小和

然后添加新数据?
Q2
How can I add more elements to an array created using ARRAY()
function??

Suppose
Dim arrhit
arrhit=ARRAY("start","dfd")
Now how can I add more elements to this array??
arrhit[1]="ssdfdf" directly or use redim first to increase the size and
then add new data??



它仍然只是一个数组而且可以成为Redim Preserve的主题

声明。

It''s still just an array and can be the subject of a Redim Preserve
statement.


Q3

数组是否可以包含超过一种数据类型?
Q3
Can an array hold elements of more than one datatype?



否;)只有一种数据类型。变种。 Variant虽然可以容纳很多

不同的数据类型。

No ;) There is only one datatype. Variant. Variant though can hold many
different datatypes.


>如果是,

内存分配是怎么做的在这种情况下??
>If yes how is the
memory allocation done in this case??



VBScript中数组中的所有元素都是变量大小的16字节。

All elements in an Array in VBScript are 16 Bytes the size of a variant.


>具有相似数据类型的元素是否存储在一起?
>are the elements with similar datatypes stored together??



数组的所有元素都分配在一个连续的
内存块中。对于许多固定长度的数据类型,如Long,boolean,currency

等,它们的值存储在变体本身中。另一个字符串

hand分配在单独的内存中,指向存储在变体中的字符串

。数组中的字符串元素与字符串本身的实际内存位置之间没有关联。

All the elements of an array are allocated in a single contiguous block of
memory. For many fixed length data types such as Long, boolean, currency
etc. their values are stored in the variant itself. Strings on the other
hand are allocated in separate memory with pointers to the strings being
stored in the variant. There is no corelation between a string elements
position in an array and the actual memory location of the string itself.


假设整数数组如此,如果数组从1000开始,因为整数

所以第二个元素将位于1002处的第三个位置1002并且很容易获得
fetch.But如果它可以保存任何数据类型的元素它如何知道

应该为一个元素获取多少字节,该元素可以是任何

数据类型?
suppose array of integers so now if array starts at 1000 since integers
so second element will be at location 1002 third at 1004 and so easy to
fetch.But if it can hold elements of any datatype how does it know that
how many bytes should be fetched for a element which can be of any
datatype??



所有元素都是16字节,存储整数没有内存优势

而不是long或甚至货币(8字节数据类型)变体

结构适合它们。

All elements are 16 bytes there is no memory advantage to store integers
instead of longs or even currency (an 8 byte datatype) since the variant
structure accommadates them.


>
>



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

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