• Dynamically allocating blocks of memory

    From john.perry@usm.edu@21:1/5 to All on Sat Jun 2 18:08:13 2018
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Diego Sardina@21:1/5 to All on Sun Jun 3 00:58:32 2018
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From August Karlstrom@21:1/5 to john.perry@usm.edu on Sun Jun 3 10:57:16 2018
    On 2018-06-03 03:08, john.perry@usm.edu wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to August Karlstrom on Sun Jun 3 02:59:57 2018
    On Sunday, June 3, 2018 at 8:57:17 AM UTC, August Karlstrom wrote:
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to Diego Sardina on Sun Jun 3 02:54:02 2018
    On Sunday, June 3, 2018 at 7:58:33 AM UTC, Diego Sardina wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From cfbsoftware@gmail.com@21:1/5 to john....@usm.edu on Sun Jun 3 04:44:29 2018
    On Sunday, June 3, 2018 at 7:24:03 PM UTC+9:30, john....@usm.edu wrote:

    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


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From August Karlstrom@21:1/5 to john.perry@usm.edu on Sun Jun 3 13:30:17 2018
    On 2018-06-03 11:59, john.perry@usm.edu wrote:
    On Sunday, June 3, 2018 at 8:57:17 AM UTC, August Karlstrom wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to cfbso...@gmail.com on Sun Jun 3 15:58:10 2018
    On Sunday, June 3, 2018 at 11:44:29 AM UTC, cfbso...@gmail.com wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to August Karlstrom on Sun Jun 3 15:59:25 2018
    On Sunday, June 3, 2018 at 11:30:18 AM UTC, August Karlstrom wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to john....@usm.edu on Sun Jun 3 16:40:58 2018
    On Sunday, June 3, 2018 at 10:58:11 PM UTC, john....@usm.edu wrote:
    On Sunday, June 3, 2018 at 11:44:29 AM UTC, cfbso...@gmail.com wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Nemo@21:1/5 to john.perry@usm.edu on Sun Jun 3 20:55:26 2018
    On 03/06/2018 19:40, john.perry@usm.edu wrote:
    On Sunday, June 3, 2018 at 10:58:11 PM UTC, john....@usm.edu wrote:
    On Sunday, June 3, 2018 at 11:44:29 AM UTC, cfbso...@gmail.com wrote:
    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.

    MAS was written in Modula-2 (but never maintained, alas).

    N.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to Nemo on Mon Jun 4 02:30:02 2018
    On Monday, June 4, 2018 at 12:55:29 AM UTC, Nemo wrote:
    On 03/06/2018 19:40, john.perry@usm.edu wrote:
    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.

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From andreas.pirklbauer@gmail.com@21:1/5 to All on Thu Jun 7 06:50:16 2018
    Am Sonntag, 3. Juni 2018 09:58:33 UTC+2 schrieb 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From john.perry@usm.edu@21:1/5 to andreas.p...@gmail.com on Thu Jun 7 13:48:11 2018
    On Thursday, June 7, 2018 at 3:50:16 PM UTC+2, andreas.p...@gmail.com wrote:
    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()).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From andreas.pirklbauer@gmail.com@21:1/5 to All on Fri Jun 8 00:48:45 2018
    Am Donnerstag, 7. Juni 2018 22:48:12 UTC+2 schrieb john....@usm.edu:
    On Thursday, June 7, 2018 at 3:50:16 PM UTC+2, andreas.p...@gmail.com wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rugxulo@gmail.com@21:1/5 to john....@usm.edu on Sun Jul 15 14:05:31 2018
    Hi,

    On Sunday, June 3, 2018 at 5:59:25 PM UTC-5, john....@usm.edu wrote:
    On Sunday, June 3, 2018 at 11:30:18 AM UTC, August Karlstrom wrote:
    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

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