Reviewing the Memory class
In this section, we will demonstrate how the Memory
class (memory.cpp
and memory.h
) in LAMMPS allocates and deallocates memory blocks as requested.
The Memory
class is widely used in the LAMMPS source code, and it is often encountered in relation to data structure creation. Its three main methods – create()
, grow()
, and destroy()
– provide handles to create, extend/shrink, and release primitive data structures, respectively. By using template overrides, these methods can accommodate 1D, 2D, and 3D arrays that serve the same function.
In memory.h
, various template functions are defined for the create()
, grow()
, and destroy()
methods in different dimensions. The following screenshot shows these template functions in 1D:
As you can see, in the create()
method, TYPE
(line 44) is initially an undefined data type that is automatically...