Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

malloc with cc65

113 views
Skip to first unread message

Bill Chatfield

unread,
Dec 14, 2023, 1:53:05 PM12/14/23
to
Can cc65 really build dynamically allocated data structures like a
vector or a map, or is it better to use a static implementation?

Oliver Schmidt

unread,
Dec 14, 2023, 5:34:12 PM12/14/23
to
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

Bill Chatfield

unread,
Dec 14, 2023, 9:59:58 PM12/14/23
to
On Thu, 14 Dec 2023 22:34:07 -0000 (UTC)
Oliver Schmidt <ol...@web.de> 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
?

Oliver Schmidt

unread,
Dec 15, 2023, 7:43:52 PM12/15/23
to
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





Bill Chatfield

unread,
Dec 18, 2023, 12:58:07 AM12/18/23
to
On Sat, 16 Dec 2023 00:43:49 -0000 (UTC)
Oliver Schmidt <ol...@web.de> 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?

Oliver Schmidt

unread,
Dec 18, 2023, 2:52:11 PM12/18/23
to
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



Bill Chatfield

unread,
Dec 20, 2023, 10:52:03 AM12/20/23
to
On Mon, 18 Dec 2023 19:51:58 -0000 (UTC)
Oliver Schmidt <ol...@web.de> 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.

Peter 'Shaggy' Haywood

unread,
Dec 26, 2023, 6:03:56 PM12/26/23
to
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.
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!!

Bill Chatfield

unread,
Dec 31, 2023, 11:58:21 AM12/31/23
to
On Wed, 27 Dec 2023 10:00:43 +1100
Peter 'Shaggy' Haywood <phay...@alphalink.com.au> 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.

Peter 'Shaggy' Haywood

unread,
Jan 3, 2024, 8:05:19 AMJan 3
to
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.
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. :)

Colin Leroy-Mira

unread,
Feb 1, 2024, 3:54:21 PMFeb 1
to
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/

0 new messages