Question
· Jun 24

<STRINGSTACK> Error

I am updating a large JSON Dynamic Object. Inserting three streams using Do obj.%Set("data",pStream,"stream>base64").

Maybe I am calling Iterate() too often?

Product version: IRIS 2022.3
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2022.3 (Build 606U) Mon Jan 30 2023 09:27:12 EST [Health:5.0.0]
Discussion (2)2
Log in or sign up to continue

I did a search for STRINGSTACK. Then I was able to solve this issue by changing Write param.%ToJSON() to Do param.%ToJSON()

This is in Docs for %ToJSON():

method %ToJSON(outstrm As %Stream.Object) as %String

Convert a %DynamicAbstractObject into a JSON string.

outstrm is optional. There are a number of possibilities:
(1) Parameter outstrm is not defined and the method is called via 'DO'. In this case the JSON string is written to the current output device.
(2) Parameter outstrm is not defined and the method is called as an expression. In this case the JSON string becomes the value of the expression.
(3) Parameter outstrm is defined. If it is %Stream object then the JSON string will be written to the stream. If outstrm is present but not an object then it is presumed to be a fully qualified file specification. In that case, a %Stream.FileCharacter stream is created, linked to that file and the JSON string is written to that stream. On completion, this stream is saved. The full path to the file must be defined. If outstrm is an object but is not an instance of %Stream.Object then an exception will be thrown.

We need to see more of your code to see what is truly happening.  The routine method call Do obj.%Set("data",pStream,"stream>base64") should have no problem providing your system has enough memory to construct entire 'obj' Dynamic Object in your process memory.  Your system will want to avoid having many large Dynamic Objects in memory at the same time.  If the system runs out memory for all the active processes then the operating system will usually start aborting processes randomly until the operating system decides it now has enough free memory to continue execution.

Calling %Set(,,) to read JSON text from a very large %Stream should only use moderate size buffers on the string stack.  If a call on %Set(,,) writing from a %Stream generates a <STRINGSTACK> signal then that should be reported to InterSystems as a bug.

However, your reply mentions the %ToJSON() function method call.  Calling %ToJSON as a function will place the result on the String Stack so it is possible such a function call could signal a <STRINGSTACK> error although if the %ToJSON() function call appears in a very simple expression then I would expect a <MAXSTRING> signal instead of a <STRINGSTACK> signal.

Calling %ToJSON() or %ToJSON(outstrm) as a routine method call in a DO statement should not get either a <STRINGSTACK> or a <MAXSTRING> signal since the result is not going to an ObjectScript string value.