Table of Contents

Class MemoryError

Namespace
NumSharp
Assembly
NumSharp.dll

Python's MemoryError: an allocation that cannot be satisfied. NumSharp raises it where NumPy does, with NumPy's text: a StringDType cell that cannot be allocated, loaded or packed (Failed to allocate string in add, Failed to load string in string comparison), an iterator whose buffers cannot be allocated (Could not allocate the iterator's buffers), CPython's bare PyErr_NoMemory (an empty text), and an array allocation, as the subclass ArrayMemoryError.

public class MemoryError : OutOfMemoryException, ISerializable, INumSharpException
Inheritance
MemoryError
Implements
Derived
Inherited Members

Remarks

It derives from .NET's OutOfMemoryException, the exception with the same meaning, so a catch (OutOfMemoryException) catches it, and .NET's own allocation failures (which stay OutOfMemoryException) and NumSharp's Python-named ones are handled by one catch.

Footgun: a catch (MemoryError) does NOT catch a plain .NET OutOfMemoryException (the runtime's own, a NativeMemory failure NumSharp did not translate); catch OutOfMemoryException to handle both.

Constructors

MemoryError()

Creates the error with Python's text for a bare raise MemoryError (CPython's PyErr_NoMemory): an empty Message, as str(MemoryError()) is '' (not .NET's OutOfMemoryException default, "Insufficient memory to continue the execution of the program.").

public MemoryError()

Remarks

ToString() then starts with the class name alone, as Python's traceback prints a bare MemoryError.

MemoryError(string)

Creates the error with NumPy's message.

public MemoryError(string message)

Parameters

message string

The text, verbatim: Python's str() of the error (Failed to allocate string in add).

MemoryError(string, Exception)

Creates the error with a message and the exception that caused it: Python's raise MemoryError(message) from innerException, the cause kept in InnerException as Python keeps it in cause.

public MemoryError(string message, Exception innerException)

Parameters

message string

The text, verbatim: Python's str() of the error.

innerException Exception

The exception that led to this one (the .NET OutOfMemoryException of the failed allocation, for example), or null for none.