.NET/Link API Version 1.7 USE FRAMES

IMathLink.CreateMark Method 

Creates a mark at the current point in the incoming MathLink data stream.

[Visual Basic]
Function CreateMark() As ILinkMark
[C#]
ILinkMark CreateMark();

Remarks

Marks can returned to later, to re-read data. A common use is to create a mark, call some method for reading data, and if a MathLinkException is thrown, seek back to the mark and try a different method of reading the data.

If you create a mark, be sure to call DestroyMark to destroy it, or you will create a memory leak.

One common reason to use a mark is if you want to examine an incoming expression and branch to different code depending on some property of the expression. You want the code that actually handles the expression to see the entire expression, but you will need to read at least a little bit of the expression to decide how it must be handled (perhaps just calling GetFunction to see the head). Here is a code fragment demonstrating this technique:
string head = null;
ILinkMark mark = ml.CreateMark();
try {
    int argc;
    head = ml.GetFunction(out argc);
    ml.SeekMark(mark);
} finally {
    ml.DestroyMark(mark);
}
if (head == "foo")
    readAndHandleFoo(ml);
else if (head == "bar")
    readAndHandleBar(ml);
Note that we use try/finally to ensure that the mark is destroyed even if an exception is thrown.

Some of the usefulness of marks in the C-language MathLink API is obviated by .NET/Link's Expr class.

Exceptions

Exception TypeCondition
MathLinkExceptionOn any MathLink error.

See Also

IMathLink Interface | Wolfram.NETLink Namespace | SeekMark | DestroyMark