String Length

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
Paul Lamar
Posts: 65
Joined: 14 May 2010, 16:01 PM

String Length

Post by Paul Lamar »

Hi Don,

How do I get Option StriingSize to work
I want to send out a 1500 character string without CR or LF.

This one does not work. The string is no where near 1500
characters. It is being truncated for some strange reason.
What am I doing wrong?

Thanks for all your hard work. We are making good progress.

Paul Lamar
Attachments
Paul5-scre-shot.jpg
(90 KiB) Downloaded 1651 times
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: String Length

Post by dkinzer »

Paul Lamar wrote:How do I get Option StriingSize to work
That option only affects certain types of string definitions. By default, all String variables are of the "allocated string" type. If you turn this off (Option AllocStr Off) then Option StringSize tells how much data space should be set aside for each string defined. However, it would be unwise, even if it were possible, to set the default string size to 2000 characters.
Paul Lamar wrote:I want to send out a 1500 character string without CR or LF.
Note that String variables are limited to 255 characters maximum. See the Fundamental Data Types table. However, that limitation doesn't prevent you from sending long sequences of characters out the serial port. How you might send a particular sequence depends on the source of the data for the character sequence. An example of what I think you wanted in your test case is shown below. Note that the semicolon at the end of the Debug.Print prevents a CR/LF from being sent.

Code: Select all

Sub Main()
  Dim x as Integer
  For x = 1 to 1000
    Debug.Print "6, ";
  Next x
End Sub
One of the challenges for people that are accustomed to writing applications for larger computers (mainframes, minicomputers, PCs) it to change the way they think about RAM use when writing a microcontroller application. On the larger computers, RAM can often be considered to be of (practically) infinite size. On a microcontroller, RAM should be considered a precious and severely limited commodity. This perspective will affect how you define your data elements and how you write the code for any particular use case.

Another possible solution is to add directly to the output queue the data that you want to send. If you were sending the data out a serial port other than Com1, you would be obliged to define and initialize the output queue and add the data directly to the queue (there is no Debug.Print equivalent for Com2). The input and output queues for Com1 are pre-defined and are not directly accessible but you can get access to the queues. The code below shows how to access the default output queue for Com1. This example code does exactly the same thing as the previous example; it just uses a different mechanism to accomplish the result.

Code: Select all

Dim defCom1Queue() as Byte Based Register.TxQueue

Sub Main()
  Dim x as Integer
  For x = 1 to 1000
    Call PutQueueStr(defCom1Queue, "6, ")
  Next x
End Sub
If the character sequence is more complex, you can expand on the idea of the previous example. In the example code below, the first one thousand integers are output with comma separation.

Code: Select all

Dim defCom1Queue() as Byte Based Register.TxQueue

Sub Main()
  Dim x as Integer
  For x = 1 to 1000
	If (x > 1) Then
	  Call PutQueueByte(defCom1Queue, Asc(","))
	End If
	Call PutQueueStr(defCom1Queue, CStr(x))
  Next x
End Sub
- Don Kinzer
Paul Lamar
Posts: 65
Joined: 14 May 2010, 16:01 PM

Post by Paul Lamar »

I have a ZX1280n with a 64K static ram on board.
Is that not useful for storing strings?

I am not familiar with the term Queue.
Is that like a first in first out stack stored in RAM?

Thanks

Paul Lamar
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

Paul Lamar wrote:I have a ZX1280n with a 64K static ram on board. Is that not useful for storing strings?
Yes, and it is. Part of the available RAM is used for statically allocated strings (and other statically allocated variables), part is used for the execution stack (and local variables) and another part, the heap, is used for storing the content of dynamically allocated strings. As I mentioned, however, the String data type in ZBasic is limited to a maximum 255 characters, partly for historical reasons. For more information about the implementation of the String data type and details of how RAM is partitioned, see the links below.

String Data Type Details
Controlling the Heap Size and Main() Task Stack Size

Of course, you are free to create your own data structures or classes for managing large sequences of characters.
Paul Lamar wrote:I am not familiar with the term Queue. Is that like a first in first out stack stored in RAM?
It is. For a general description of the queue data structure, see the Wikipedia Article on Queues. For information about queues specific to ZBasic, see the Section 3.4 Queues in the ZBasic Refererence Manual.
- Don Kinzer
Post Reply