• blackbrook@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    7 hours ago

    I’m drawing on some old memories here, so I could be mistaken, but I don’t think the stack is read only, not in C anyway or in the underlying machine code. If it is faster it has to do with greater overhead needed managing the larger heap and perhaps being more efficient to push and pop with small offsets to a local stack frame vs large absolute addresses.

    • thingsiplay@lemmy.ml
      link
      fedilink
      arrow-up
      1
      ·
      7 hours ago

      but I don’t think the stack is read only

      I don’t mean the stack is read only (edit: yes I meant that in my previous reply, but got confused myself, I actually never thought the entire stack being read only, I was only thinking about those specific variables and literal strings, sorry for confusion), but certain variables holding values that are only used to read and not change. In example you cannot change literals, therefore they are read only values. In example if you have a program that prints “Hello Lemmy”, that string is a literal that cannot be altered, and it is found in the application itself, as part of the binary. That part maybe is marked as read only?