• malloc with cc65

    From Bill Chatfield@21:1/5 to All on Thu Dec 14 13:53:00 2023
    Can cc65 really build dynamically allocated data structures like a
    vector or a map, or is it better to use a static implementation?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Schmidt@21:1/5 to All on Thu Dec 14 22:34:07 2023
    Hi Bill,

    Can cc65 really build dynamically allocated data structures like a
    vector or a map, or is it better to use a static implementation?

    1. cc65 comes with a fully functional heap manager incl. heap
    defragmentation.

    2. The cc65 optimizer (always compile with -O) knows about "pointer
    constants" (in contrast to pointer variables) so the code to access them is usually faster/smaller.

    Regards,
    Oliver

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bill Chatfield@21:1/5 to Oliver Schmidt on Thu Dec 14 21:59:55 2023
    On Thu, 14 Dec 2023 22:34:07 -0000 (UTC)
    Oliver Schmidt <[email protected]> wrote:

    1. cc65 comes with a fully functional heap manager incl. heap defragmentation.

    That is fantastic!

    2. The cc65 optimizer (always compile with -O) knows about "pointer constants" (in contrast to pointer variables) so the code to access
    them is usually faster/smaller.

    I'm not sure where a pointer constant would be used in a C program.
    Would this be an address defined with #define or something like:
    const char *KBD
    ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Schmidt@21:1/5 to All on Sat Dec 16 00:43:49 2023
    Hi Bill,

    2. The cc65 optimizer (always compile with -O) knows about "pointer
    constants" (in contrast to pointer variables) so the code to access
    them is usually faster/smaller.

    I'm not sure where a pointer constant would be used in a C program.

    I meant the term in this sense...

    An integer variable:
    int a

    An integer constant:
    5

    Setting the variable to the constant:
    a = 5

    A pointer variable:
    int *b

    A pointer constant:
    int c[10]

    Setting the variable to the constant:
    b = c

    What I state above means that using c is faster/smaller than using b like
    this:
    *c = 2
    *b = 2

    Regards,
    Oliver

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bill Chatfield@21:1/5 to Oliver Schmidt on Mon Dec 18 00:58:02 2023
    On Sat, 16 Dec 2023 00:43:49 -0000 (UTC)
    Oliver Schmidt <[email protected]> wrote:

    What I state above means that using c is faster/smaller than using b
    like this:
    *c = 2
    *b = 2

    You're hard-coding the array into zero-page absolute address 2. Am I understanding that correctly and is that what you meant?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Oliver Schmidt@21:1/5 to All on Mon Dec 18 19:51:58 2023
    Hi Bill,

    What I state above means that using c is faster/smaller than using b
    like this:
    *c = 2
    *b = 2

    You're hard-coding the array into zero-page absolute address 2. Am I understanding that correctly and is that what you meant?

    No, the syntax above isn't for assigning a value to a pointer. It's for assigning a value to the address the pointer points to.

    Regards,
    Oliver

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bill Chatfield@21:1/5 to Oliver Schmidt on Wed Dec 20 10:52:00 2023
    On Mon, 18 Dec 2023 19:51:58 -0000 (UTC)
    Oliver Schmidt <[email protected]> wrote:

    No, the syntax above isn't for assigning a value to a pointer. It's
    for assigning a value to the address the pointer points to.

    OMG, it's been too long since I've written C code. Of, course you're
    right and I knew that. The overloading of the * operator in one place
    to define a pointer and in another place, the exact opposite, to access
    the data pointed to by a pointer, has always perplexed me.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter 'Shaggy' Haywood@21:1/5 to All on Wed Dec 27 10:00:43 2023
    Groovy hepcat Bill Chatfield was jivin' in comp.sys.apple2.programmer on
    Thu, 21 Dec 2023 02:52 am. It's a cool scene! Dig it.

    On Mon, 18 Dec 2023 19:51:58 -0000 (UTC)
    Oliver Schmidt <[email protected]> wrote:

    No, the syntax above isn't for assigning a value to a pointer. It's
    for assigning a value to the address the pointer points to.

    OMG, it's been too long since I've written C code. Of, course you're
    right and I knew that. The overloading of the * operator in one place
    to define a pointer and in another place, the exact opposite, to
    access the data pointed to by a pointer, has always perplexed me.

    There's no overloading going on here (notwithstanding its use the multiplication operator). It's really quite simple. The * operator
    means "the object pointed at". When used in a declaration it still
    means "the object pointed at". A pointer to foo (where foo is a type) declaration essentially means, "Declare an object which is a pointer
    such that the object pointed at by it is a foo."

    --


    ----- Dig the NEW and IMPROVED news sig!! -----


    -------------- Shaggy was here! ---------------
    Ain't I'm a dawg!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bill Chatfield@21:1/5 to Peter 'Shaggy' Haywood on Sun Dec 31 11:58:19 2023
    On Wed, 27 Dec 2023 10:00:43 +1100
    Peter 'Shaggy' Haywood <[email protected]> wrote:

    There's no overloading going on here (notwithstanding its use the multiplication operator). It's really quite simple. The * operator
    means "the object pointed at". When used in a declaration it still
    means "the object pointed at". A pointer to foo (where foo is a type) declaration essentially means, "Declare an object which is a pointer
    such that the object pointed at by it is a foo."

    I see what you're saying, after much mind bending. Maybe that is the
    correct way to think about it.

    The way I was thinking about it, in the declaration, the * produces a
    pointer. In an expression the * produces data from a pointer.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter 'Shaggy' Haywood@21:1/5 to All on Wed Jan 3 19:05:57 2024
    Groovy hepcat Bill Chatfield was jivin' in comp.sys.apple2.programmer on
    Mon, 1 Jan 2024 03:58 am. It's a cool scene! Dig it.

    On Wed, 27 Dec 2023 10:00:43 +1100
    Peter 'Shaggy' Haywood <[email protected]> wrote:

    There's no overloading going on here (notwithstanding its use the
    multiplication operator). It's really quite simple. The * operator
    means "the object pointed at". When used in a declaration it still
    means "the object pointed at". A pointer to foo (where foo is a type)
    declaration essentially means, "Declare an object which is a pointer
    such that the object pointed at by it is a foo."

    I see what you're saying, after much mind bending. Maybe that is the
    correct way to think about it.

    The way I was thinking about it, in the declaration, the * produces a pointer. In an expression the * produces data from a pointer.

    Dereferences the pointer, yeah, that's basically correct. But you have
    to sort-of shift your thinking sideways a bit to understand what's
    really going on. A declaration containing an asterisk means "declare an
    object that points at foo". That's perhaps a more idiomatic but less technically precise way of saying "declare an object which is a pointer
    such that the object pointed at by it is a foo." The asterisk itself
    means "the object pointed at".
    It may sound odd at first, but makes perfect sense once you get it. :)

    --


    ----- Dig the NEW and IMPROVED news sig!! -----


    -------------- Shaggy was here! ---------------
    Ain't I'm a dawg!!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Colin Leroy-Mira@21:1/5 to All on Thu Feb 1 21:54:13 2024
    Hi,

    What I state above means that using c is faster/smaller than using b
    like this:
    *c = 2
    *b = 2

    Unless you want to iterate, in which case

    while (*b) {
    ... do something with *b...
    b++;
    }

    is much faster than

    while (c[i]) {
    ... do something with c[i]...
    i++;
    }
    --
    Colin
    https://www.colino.net/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)