Discussion:
Dynamically allocating blocks of memory
(too old to reply)
j***@usm.edu
2018-06-03 01:08:13 UTC
Permalink
Hello all

For many problems it is not always known in advance how many copies of an object will be. For instance, suppose I want to write a program that will manipulate matrices, but I don't know in advance the size of the matrix, because I don't know whether the end user needs a 2x2 matrix or a 10000x100 matrix.

One can, of course, decide in advance that the system will handle a "maximum" size matrix (say) and restrict the user to that (a la TeX and LaTeX***), but a more flexible approach is to allocate a block of memory whose size is not known until runtime. I've seen some discussion in comp.lang.oberon's history about the NEW(ptr, num) command that exists in Oberon-2 and in Wirth's Oberon extension for the ARM, but what I've not seen is an answer to this question:

Is the Oberon and/or Oberon-07 way to approach this scenario: the former (everything decided at compile-time)? Or is there a way to allocate blocks of memory whose sizes are unknown until runtime?

(I'm sorry if this has been asked before, but I did a search & didn't find an answer to this.)

regards
john perry

***For example, https://tex.stackexchange.com/questions/26205/increase-latex-capacity
Diego Sardina
2018-06-03 07:58:32 UTC
Permalink
The feature you are looking for is called pointers to open array.

Oberon and Oberon-07 don't support this feature, but Oberon-2 and Component Pascal do.

Although they are useful for the reasons you said, they add complexity in runtime (especially in a garbage collected language).

--
Diego Sardina
j***@usm.edu
2018-06-03 09:54:02 UTC
Permalink
Post by Diego Sardina
The feature you are looking for is called pointers to open array.
Oberon and Oberon-07 don't support this feature, but Oberon-2 and Component Pascal do.
Although they are useful for the reasons you said, they add complexity in runtime (especially in a garbage collected language).
I understand from the previous discussions that this solution is unavailable; my question was, how *does* one deal with this situation in Oberon? The impression I have is that one has to decide in advance.
c***@gmail.com
2018-06-03 11:44:29 UTC
Permalink
Post by j***@usm.edu
I understand from the previous discussions that this solution is unavailable; my question was, how *does* one deal with this situation in Oberon?
I wouldn't use a general-purpose programming language for these sorts of tasks. Versions of Oberon exist with extended features specifically designed to tackle mathematical problems of this sort. e.g. Read the paper titled 'A Mathematical Programming Language Extension for Multilinear Algebra' by Felix Friedrich et al. You can download a copy from his webpage at ETH:

https://www.inf.ethz.ch/personal/felixf/pub.html

Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
j***@usm.edu
2018-06-03 22:58:10 UTC
Permalink
Post by c***@gmail.com
I wouldn't use a general-purpose programming language for these sorts of tasks.
It was not my intent; it was an example of the situation.

I do thank you for the links to Felix Friedrich's work with mathematics in Active Oberon; those are interesting.
j***@usm.edu
2018-06-03 23:40:58 UTC
Permalink
Post by j***@usm.edu
Post by c***@gmail.com
I wouldn't use a general-purpose programming language for these sorts of tasks.
It was not my intent; it was an example of the situation.
Having said that, though, I should point out that most computer algebra systems I know of, and/or whose code I've looked at, have a very large C or C++ core, and both of these are considered general-purpose, as well. Some of the older ones (e.g., Macsyma/Maxima) use LISP.
Nemo
2018-06-04 00:55:26 UTC
Permalink
Post by j***@usm.edu
Post by j***@usm.edu
Post by c***@gmail.com
I wouldn't use a general-purpose programming language for these sorts of tasks.
It was not my intent; it was an example of the situation.
Having said that, though, I should point out that most computer algebra systems
I know of, and/or whose code I've looked at, have a very large C or
C++ core,
Post by j***@usm.edu
and both of these are considered general-purpose, as well. Some of
the older
Post by j***@usm.edu
ones (e.g., Macsyma/Maxima) use LISP.
MAS was written in Modula-2 (but never maintained, alas).

N.
j***@usm.edu
2018-06-04 09:30:02 UTC
Permalink
Post by j***@usm.edu
Post by j***@usm.edu
Having said that, though, I should point out that most computer algebra systems
I know of, and/or whose code I've looked at, have a very large C or
C++ core,
Post by j***@usm.edu
and both of these are considered general-purpose, as well. Some of
the older
Post by j***@usm.edu
ones (e.g., Macsyma/Maxima) use LISP.
MAS was written in Modula-2 (but never maintained, alas).
IIRC one of CoCoA's developers told me they at least considered Modula-2, and perhaps even started off with it, but eventually settled on C/C++. I wish I remembered that conversation better.

Singular is written in C, but its codebase #define's a "loop" command that is essentially Modula-2's, and the lead developer has cited Modula-2 as showing this is a good idea.
a***@gmail.com
2018-06-07 13:50:16 UTC
Permalink
Post by Diego Sardina
The feature you are looking for is called pointers to open array.
Oberon and Oberon-07 don't support this feature, but Oberon-2 and Component Pascal do.
Although they are useful for the reasons you said, they add complexity in runtime (especially in a garbage collected language).
--
Diego Sardina
Perhaps this is useful: https://github.com/andreaspirklbauer/Oberon-generic-heap-allocation

This brings NEW(ptr, size) to Oberon-07.
j***@usm.edu
2018-06-07 20:48:11 UTC
Permalink
Post by a***@gmail.com
Perhaps this is useful: https://github.com/andreaspirklbauer/Oberon-generic-heap-allocation
This brings NEW(ptr, size) to Oberon-07.
Thank you for the reply;I appreciate it very much. It prompted me to look more carefully at the Oberon System's setup & I noticed that it defines some methods to do this very thing (Kernel.GetBlock...(), Kernel.New()).
a***@gmail.com
2018-06-08 07:48:45 UTC
Permalink
Post by j***@usm.edu
Post by a***@gmail.com
Perhaps this is useful: https://github.com/andreaspirklbauer/Oberon-generic-heap-allocation
This brings NEW(ptr, size) to Oberon-07.
Thank you for the reply;I appreciate it very much. It prompted me to look more carefully at the Oberon System's setup & I noticed that it defines some methods to do this very thing (Kernel.GetBlock...(), Kernel.New()).
If you look carefully at the code in the above repository, it uses just these Kernel procedures.

The management of dynamic storage (heap) is explained in detail in ch. 8. of the book "Project Oberon", available at http://www.projectoberon.com . Oberon uses a very straightforward allocation strategy.
August Karlstrom
2018-06-03 08:57:16 UTC
Permalink
Post by j***@usm.edu
For many problems it is not always known in advance how many copies
of an object will be. For instance, suppose I want to write a program
that will manipulate matrices, but I don't know in advance the size
of the matrix, because I don't know whether the end user needs a 2x2
matrix or a 10000x100 matrix.
At least, Oberon supports open arrays of more than one dimension, so you
can write a matrix library that will handle matrices of any size.

-- August
j***@usm.edu
2018-06-03 09:59:57 UTC
Permalink
Post by August Karlstrom
At least, Oberon supports open arrays of more than one dimension, so you
can write a matrix library that will handle matrices of any size.
Thank you; that is a good point. Are you saying that it is in fact a matter of deciding all possible dimensions in advance?
August Karlstrom
2018-06-03 11:30:17 UTC
Permalink
Post by j***@usm.edu
Post by August Karlstrom
At least, Oberon supports open arrays of more than one dimension, so you
can write a matrix library that will handle matrices of any size.
Thank you; that is a good point. Are you saying that it is in fact a
matter of deciding all possible dimensions in advance?
I'm not saying that it solves the problem, instead the problem is moved
from the server module to the client module. Like you, I don't know what
the best approach is if your application needs to handle matrices (or
arrays) of arbitrary size. Using linked arrays is one approach.


-- August
j***@usm.edu
2018-06-03 22:59:25 UTC
Permalink
Post by August Karlstrom
I'm not saying that it solves the problem, instead the problem is moved
from the server module to the client module. Like you, I don't know what
the best approach is if your application needs to handle matrices (or
arrays) of arbitrary size. Using linked arrays is one approach.
You're right. It could be done that way. Tough, though.
r***@gmail.com
2018-07-15 21:05:31 UTC
Permalink
Hi,
Post by j***@usm.edu
Like you, I don't know what the best approach is if your
application needs to handle matrices (or arrays) of arbitrary
size. Using linked arrays is one approach.
You're right. It could be done that way. Tough, though.
It's not necessarily that tough, just different. But, indeed,
not every potential solution is easy or portable or best-suited
to all targets. Use whatever tools work best, based upon
actual requirements, not ideological purity. (Still, it
doesn't hurt to ask what the best existing method is.)

For instance, original Oberon (1990) only had SYSTEM.NEW(v,n):

http://www.ethoberon.ethz.ch/oreport.html#SYSTEM

12. The Module SYSTEM -> Proper procedures

Name Argument types Function
---- -------------- --------
NEW(v, n) v: any pointer type allocate storage block of n bytes
n: integer type assign its address to v

Loading...