473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Buffer problem

Hi,

I posted this earlier today with no help. I'm trying
agin as I am desparate(sp?).

Hi there,

I'm trying to convert part of a byte array into a series
of fixed length strings but half way through the for loop
I get an error that I'm accessing outside the buffer
bounds.

The error:

An unhandled exception of
type 'System.ArgumentOutOfRangeException' occurred in
mscorlib.dll

Additional information: Index and count must refer to a
location within the buffer.

The loop:

Private Sub initAttribText(ByVal bData() As Byte)
Dim pos As Integer = charSize * 100

For i As Integer = 0 To 39
theAttribText(i) = _
System.Text.ASCIIEncoding.ASCII.GetString
(bData, arrayStart + (i * pos),
(arrayStart + (i * pos)) + 99)
Next i

arrayStart += (40 * pos)
End Sub

The byte array bData is of length 4481.
The value of i at the point of the error is 21.
The value of arrayStart is 160.
The value of pos is 100.
So the indexes at the point of the error are 2260, 2359.

IF anyone can tell me the cause of the error I would be
very greatful!! Clearly the indexes are within the bounds
of the byte array so there must be some other cause but I
can't see it.

Thanks,

Denis
..

The byte array comes is marshalled from an IntPtr. The
IntPtr is returned by a C dll function that I have access
using the DllImportAttribute class.

Any help would be really appreciated. Unfortunately I
cannot post much more code than this. But I can say this
is the only case that htis approach is not working. For
Accessing integer arrays and boolean arrays I am having
no problems.

Denis
Nov 20 '05 #1
5 3142
Cor
Hi Denis,

As far as we can see is arraystart global,

And therefore it maybe will work the first time,
but the second time the start point can be more than 4000
4000 + 5*100 = out of range

That is what I can see with the code you did suply, so you first have to
check what is the startpositon of arrayStart before the routine starts.

I hope this did help?

Cor

Private Sub initAttribText(ByVal bData() As Byte)
Dim pos As Integer = charSize * 100

For i As Integer = 0 To 39
theAttribText(i) = _
System.Text.ASCIIEncoding.ASCII.GetString
(bData, arrayStart + (i * pos),
(arrayStart + (i * pos)) + 99)
Next i

arrayStart += (40 * pos)
End Sub

The byte array bData is of length 4481.
The value of i at the point of the error is 21.
The value of arrayStart is 160.
The value of pos is 100.
So the indexes at the point of the error are 2260, 2359.

Nov 20 '05 #2
Hi,

The arrayStart is global and only changes after the
subroutine is done so the arrayStart of the next
subroutine is correct. i and pos supply the indexwhen
added to arrayStart.

Denis
-----Original Message-----
Hi Denis,

As far as we can see is arraystart global,

And therefore it maybe will work the first time,
but the second time the start point can be more than 4000
4000 + 5*100 = out of range

That is what I can see with the code you did suply, so you first have tocheck what is the startpositon of arrayStart before the routine starts.
I hope this did help?

Cor

Private Sub initAttribText(ByVal bData() As Byte)
Dim pos As Integer = charSize * 100

For i As Integer = 0 To 39
theAttribText(i) = _
System.Text.ASCIIEncoding.ASCII.GetString
(bData, arrayStart + (i * pos),
(arrayStart + (i * pos)) + 99)
Next i

arrayStart += (40 * pos)
End Sub

The byte array bData is of length 4481.
The value of i at the point of the error is 21.
The value of arrayStart is 160.
The value of pos is 100.
So the indexes at the point of the error are 2260,
2359.

.

Nov 20 '05 #3
"Denis C" <an*******@discussions.microsoft.com> schrieb

I posted this earlier today with no help. I'm trying
agin as I am desparate(sp?).


Sorry that I did not answer in the other thread about the same problem. I
pasted your code and tried to understand it, but I failed. Sorry.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Cor
Hi Dennis,
This is at the end of your sub
arrayStart += (40 * pos)

But it is probably not the error,
The function you uses is as far as I can see
(bytearray,index,count)
and not as you uses it
(bytearray,index,end)

theAttribText(i) = _
System.Text.ASCIIEncoding.ASCII.GetString
(bData, arrayStart + (i * pos),
(arrayStart + (i * pos)) + 99)

So the error I saw will probably only be in the next visit to the function.

Cor
The arrayStart is global and only changes after the
subroutine is done so the arrayStart of the next
subroutine is correct. i and pos supply the indexwhen
added to arrayStart.

Nov 20 '05 #5
-----Original Message-----
Hi Dennis,
This is at the end of your sub
arrayStart += (40 * pos)

But it is probably not the error,
The function you uses is as far as I can see
(bytearray,index,count)
That's it I think!! Count not end, I was using it
wrong!! Thanks so much!!

Denisand not as you uses it
(bytearray,index,end)

theAttribText(i) = _
System.Text.ASCIIEncoding.ASCII.GetString
(bData, arrayStart + (i * pos),
(arrayStart + (i * pos)) + 99)

So the error I saw will probably only be in the next visit to the function.
Cor
The arrayStart is global and only changes after the
subroutine is done so the arrayStart of the next
subroutine is correct. i and pos supply the indexwhen
added to arrayStart.

.

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: gaool | last post by:
Hello, I wrote a python script (python 2.3.3) to send some commands to a programm and to show on the screen the responses of this programm. I use "Pipedream.py" module in my script to speak with...
1
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled....
5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
5
by: Tim | last post by:
Hi, I'm experiencing some problem with the following code: st = File.Open(sFilename, FileMode.Open, FileAccess.ReadWrite) br = New BinaryReader(st) Do Until br.PeekChar = -1 Dim buffer()...
12
by: Jim Rodgers | last post by:
I have a big asp file that has an error under certain conditions -- totally repeatable. However, it only fails when I set response.buffer = True at the top. WHen I set it False in order to debug...
6
by: nickdu | last post by:
I usually try to stay away from _alloca(). However, I'm considering using it for a logging function. Our current logging function maintains its own buffer which it grows to fit the string being...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
9
by: Notebooker | last post by:
Hello, I'm an intermediate noob reading-in data from ascii-file using an ifstream object. I have specified a c-style string buffer with size of type size_t and I am specifying to use this...
4
by: aki | last post by:
Hi all, i am writing codes for implementing network protocols. i have written a method which is receiving a packet from network. i have assumed that the packet i will receive will be of type...
4
by: Aditya | last post by:
Hi I am using recv() from socket.h in one of my TCP-client projects. The problem is that the buffer variable in recv(socketDescriptor, buffer, flags) points to some stray location and when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.