Menu

String Arrays in GCBASIC - Implementation Discussion

Anobium
2025-01-11
2025-01-13
  • Anobium

    Anobium - 2025-01-11

    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

    1. Memory Constraints
    2. Most of our target chips have very limited RAM
    3. Need to balance array size vs available memory
    4. Static vs dynamic allocation considerations
    5. Impact on existing variable space

    6. String Length Considerations

    7. Maximum string length per array element
    8. Whether to support variable length strings within arrays, or, if this even possible
    9. Memory overhead for length tracking
    10. 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

    1. Memory Efficiency
    2. Need to work on chips with as little as 128 bytes RAM
    3. Must coexist with other variables
    4. Minimize overhead per array

    5. Performance Considerations

    6. String copying overhead
    7. Array access speed
    8. Impact on interrupt handling
    9. Memory fragmentation management

    Specific Questions for the Community

    1. What's the minimum useful array size for your applications?
    2. What string lengths do you typically need?
    3. Would you prefer fixed or variable length strings within arrays?
    4. How important is dynamic resizing?
    5. What error handling mechanisms would be most useful?
    6. 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

     
    • jackjames

      jackjames - 2025-01-13

      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).

       
      • Anobium

        Anobium - 2025-01-13

        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.

         
    • jackjames

      jackjames - 2025-01-13

      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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.