String Arrays in GCBASIC - Implementation Discussion
Dear GCBASIC Community,
I'm looking to gather input on implementing String Arrays in GCBASIC. This would be a significant enhancement to our string handling capabilities, but we need to carefully consider various technical aspects and constraints. I'd appreciate your thoughts and requirements on the following points:
Current Limitations & Challenges
Memory Constraints
Most of our target chips have very limited RAM
Need to balance array size vs available memory
Static vs dynamic allocation considerations
Impact on existing variable space
String Length Considerations
Maximum string length per array element
Whether to support variable length strings within arrays, or, if this even possible
Memory overhead for length tracking
Potential fragmentation issues
Proposed Implementation Questions
Memory Management
Should we implement fixed-size arrays only?
How should we handle memory allocation on small RAM devices (like legacy 16F chips)?
Should we implement garbage collection for dynamic strings?
What's an acceptable memory overhead for array management?
Syntax & Usage
Proposed syntax: Dim myStrings(10) As String * 20 // Array of 10 strings, max 20 chars each
Alternative: Dim myStrings(10) As String // With compiler-defined max length
How should we handle string assignment/copying?
Should we support string slicing within arrays?
Error Handling
How to handle out-of-memory conditions?
Array bounds checking implementation
String overflow handling
Error reporting mechanism
Implementation Constraints
Memory Efficiency
Need to work on chips with as little as 128 bytes RAM
Must coexist with other variables
Minimize overhead per array
Performance Considerations
String copying overhead
Array access speed
Impact on interrupt handling
Memory fragmentation management
Specific Questions for the Community
What's the minimum useful array size for your applications?
What string lengths do you typically need?
Would you prefer fixed or variable length strings within arrays?
How important is dynamic resizing?
What error handling mechanisms would be most useful?
What string manipulation functions are essential for array elements?
Proposed Memory Models
Model A: Fixed Size, Fixed Length
Dim strArray(5) As String * 10 ' 50 bytes + overhead
' Each string exactly 10 bytes
' No length tracking needed
' Fastest access
' Most memory efficient
Model B: Fixed Size, Variable Length
Dim strArray(5) As String ' 55 bytes (assuming 10 char max + length byte)
' Length byte per string
' More flexible
' Slightly more overhead
' Potential fragmentation
Please share your use cases, requirements, and preferences. Specific examples of how you would use string arrays in your applications would be especially helpful.
Thank you for your input!
Evan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think fixed length string Arrays are easier to handle.
Arrays with variable length strings allow you to optimize the available memory but are more complex to manage. In MikroBasic the string is always terminated with a 0 (null) character. You could use this system to mark the end of the string and find the pointer to the following string (if it exists).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Another very useful feature present in the C language that could be implemented in GBCasic is the 'Union'.
In particular, a union has members like a data structure, but at any instant of time only one of them can contain a valid value. This is because the members of a union share the same memory space.
However, unlike a data structure, the compiler only allocates the space needed to accommodate the largest member. This means that all members of a union share the same memory space.
Therefore, when you assign a value to a member of a union, the value of all other members is overwritten.
The declaration of this union is very similar to the declaration of a structure. For example:
union Example {
int i;
word w;
byte b;
}
The main difference between the struct and the union is that the members of the struct are stored in separate memory spaces (i.e. different addresses) while the members of the union are stored in the same memory space (i.e. the same address).
To create it:
Union Example NameOfUnion
It is very useful for creating a support variable where you can temporarily insert data of different types to be processed later.
In this way the memory allocated is only that used by the largest data type.
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
String Arrays in GCBASIC - Implementation Discussion
Dear GCBASIC Community,
I'm looking to gather input on implementing String Arrays in GCBASIC. This would be a significant enhancement to our string handling capabilities, but we need to carefully consider various technical aspects and constraints. I'd appreciate your thoughts and requirements on the following points:
Current Limitations & Challenges
Impact on existing variable space
String Length Considerations
Proposed Implementation Questions
Memory Management
Syntax & Usage
Dim myStrings(10) As String * 20
// Array of 10 strings, max 20 chars eachDim myStrings(10) As String
// With compiler-defined max lengthError Handling
Implementation Constraints
Minimize overhead per array
Performance Considerations
Specific Questions for the Community
Proposed Memory Models
Model A: Fixed Size, Fixed Length
Model B: Fixed Size, Variable Length
Please share your use cases, requirements, and preferences. Specific examples of how you would use string arrays in your applications would be especially helpful.
Thank you for your input!
Evan
I think fixed length string Arrays are easier to handle.
Arrays with variable length strings allow you to optimize the available memory but are more complex to manage. In MikroBasic the string is always terminated with a 0 (null) character. You could use this system to mark the end of the string and find the pointer to the following string (if it exists).
Agree. Fixed lengths should be easier to handle.
I plan to retain the leading byte method of string descriptions. As all the existing string handlers will then work.
Another very useful feature present in the C language that could be implemented in GBCasic is the 'Union'.
In particular, a union has members like a data structure, but at any instant of time only one of them can contain a valid value. This is because the members of a union share the same memory space.
However, unlike a data structure, the compiler only allocates the space needed to accommodate the largest member. This means that all members of a union share the same memory space.
Therefore, when you assign a value to a member of a union, the value of all other members is overwritten.
The declaration of this union is very similar to the declaration of a structure. For example:
union Example {
int i;
word w;
byte b;
}
The main difference between the struct and the union is that the members of the struct are stored in separate memory spaces (i.e. different addresses) while the members of the union are stored in the same memory space (i.e. the same address).
To create it:
Union Example NameOfUnion
It is very useful for creating a support variable where you can temporarily insert data of different types to be processed later.
In this way the memory allocated is only that used by the largest data type.