[IronPython] Q: How to resize an System.Array ?
Dino Viehland
dinov at exchange.microsoft.com
Fri Jan 12 19:42:33 CET 2007
dataHeap = System.Array[System.Byte] is just remembering the array type, not creating the actual array instance. What I think you want is:
import System
dataHeap = System.Array.CreateInstance(System.Byte, 4096) # creates a byte array 4k long
if you want to then resize the array:
dataHeap = Array.Resize[System.Byte](dataHeap, newSize) # resizes the array to the new size
Both of those seem to work.
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Haibo Luo
Sent: Friday, January 12, 2007 8:50 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Q: How to resize an System.Array ?
dateHeap is a type in your code snippet below. The following code works, but I am not 100% sure it is expected to see the exception thrown for the last line. Dino?
>>> import System
>>> t = System.Array[System.Byte]
>>> a = t([1,2])
>>> System.Array.Resize[System.Byte](a, 10)
System.Byte[](1, 2, 0, 0, 0, 0, 0, 0, 0, 0)
>>> System.Array.Resize(a, 10)
Traceback (most recent call last):
File , line 0, in <stdin>##27
TypeError: no callable targets, if this is a generic method make sure specify the type parameters
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Bernd Viehmann
Sent: Friday, January 12, 2007 3:47 AM
To: users at lists.ironpython.com
Subject: [IronPython] Q: How to resize an System.Array ?
Hi,
I have some problems with using >System.Array<-instances in ipy.
I have found a way to create them, but not how to use the :-). Basically
i want 2 use a MemoryStream in the following way ( kind of C#-way :-) ) :
dataHeap = System.Array[System.Byte]
dataHeap.Resize(dataHeap,4096)
bytesRead = reader.Read(dataHeap, 0, PiceLength)
But ipy does not understand me. I receive the message:
dataHeap.Resize(dataHeap,4096)
TypeError: no callable targets, if this is a generic method make sure
specify the type parameters
Any ideas who to use the mem-stream?
Thanks much.
Bernd
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list