On Monday, March 15, 2021 at 8:29:40 AM UTC+11, Rod Pemberton wrote:
> > I want the compiler to be able to generate far data pointers
> > and near code pointers.
> The C specifications don't support segmented address pointers.
C90+ will (or may).
> So, multiple calls to malloc(), e.g., two 4GiB calls, would work,
> IF AND ONLY IF,
> you can guarantee that the memory allocator allocates both blocks
> contiguously. E.g.,
>
> __set_contiguous_multiple_allocations(1);
> malloc(4GiB);
> malloc(4GiB);
> __set_contiguous_multiple_allocations(0);
Yes, you may be able to get that to work, but I think
the correct abstraction is far_malloc64().
> > I don't want to burden the compiler with a formal "long long"
> > data type.
> >
> > I want long to be 32-bits.
> >
> > I want to declare a:
> >
> > char huge *p;
> >
> > to point to my above-size_t memory block.
>
> But, in this example, you have "to burden the compiler with a formal"
> "huge" pointer type ... Same difference?
No. Most implementations will be allowed to
get away with:
#define huge
#define far_malloc(a, b) ((a == 0) ? NULL : malloc(b))
> I.e., I see an advantage to
> supporting "long long"
It's too much work to expect an MSDOS compiler
to do all that for you. You may as well ask for a
long long long long long long too. This is not the
right approach. C90 had it right, stopping at long,
but allowing that to be 64-bit or 128-bit or 256-bit
or whatever technology allows.
> but see no advantage to support "huge" or "far"
> or "near", if you don't need to do so.
The advantage is that you don't need new
instructions or registers or calling conventions
on S/370 to suddenly support accessing more
than 4 GiB of memory. You simply need to
recompile your program with an appropriate
compiler.
Quibbling aside.
> > I don't expect to be able to do a strlen() of p
> Why not?
That's precisely what size_t is for. That's what you
can support "normally". If you can support 64-bit
strlen() then set size_t to a 64-bit value.
> strlen() is just a loop that detects a zero byte/word (which usually
> maps to a nul char '\0' on most implementations, i.e., because
> they're the same size byte/word and char for most platforms).
Yes, and it will cut out at size_t and wrap.
> strlen() should work on an infinite length string.
There's not many infinite things in this world. :-)
> > but I do expect to be able to do p++ to traverse the entire 8 GiB
> > memory block
> Same thing. No difference.
Nope. Segmented memory will wrap when the offset
reaches the maximum.
> > perhaps looking for the character 'Q', with the segment
> > register being automatically adjusted by the compiler, at its
> > discretion.
> What?
>
> Are you saying you want another string terminator like nul '\0' for C
> but using the character 'Q'? What for? Unnecessary...
No, it was an example application. If you have a
simple application that looks for a 'Q' then you
can go while (*p != 'Q') p++;
Then you will know where 'Q' is. Don't look at me, I
don't write many applications. :-)
> > I'd like to represent a 64-bit value to be given to huge_malloc()
> > by two unsigned longs, both containing 32-bit values, even on
> > machines where longs are 128 bits.
> Instead of passing a 64-bit value into a malloc() variant, why wouldn't
> you have a malloc() variant that allocated 4KB or 64KB blocks of memory
> at a time, instead of allocating bytes of memory at a time like
> malloc()? E.g., 32-bit x (4KB per allocation). This wouldn't give you
> a 64-bit address range, but it would eliminate the need for extending
> integers or pointers, or passing in a segment etc.
The whole point is to get a 64-bit address range.
On systems that only have 32-bit registers, but
lots of memory.
> > I'd also like a:
> > char huge *z;
> > z = addhuge(p, unsigned long high, unsigned long low);
> >
> > A subhuge too.
> You're beginning to really complicate things ...
Adding a 64-bit value to a 64-bit pointer on a system
with only 32-bit registers requires a function call, or
a large macro.
It's a complicated scenario. That's why we have a
separation between near and far memory. Near
memory is simple.
> > The same functions can exist in all compilers, including
> > MSDOS, even if they just return NULL for huge_malloc()
> > for obvious reasons. But even MSDOS can give you a
> > memory block bigger than 64k, so if you request 128k
> > using huge_malloc(), no worries, you'll get it.
> AISI, your only real problem is with values larger than 32-bit. You
Yes, 32 is already difficult for 8086 to handle. I'm not
willing to make matters worse. God only knows how
the Commodore 64 supports 32-bit longs. I haven't
reached that point yet, but it's on my journey. I want to
write a C program for the C64.
> need an additional keyword to indicate the increased size, be it "long
> long" for integers/pointers or just a "huge" or "far" for pointers.
The additional keyword huge/far is dead simple to
implement on a C64 or standard S/370. It is simply
ignored.
long long is ridiculous unless the standard allows
it to be 32-bits or 16 bits. But that completely
defeats the purpose of why it is being added.
BFN. Paul.