internals_patterns.html from PovClipse at Krugle
Show internals_patterns.html syntax highlighted
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>5.4. Patterns</title><link rel="stylesheet" href="megapov.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="MegaPOV Documentation"><link rel="up" href="internals.html" title="Chapter 5. Internals"><link rel="previous" href="parser.html" title="5.3. Parser"><link rel="next" href="internals_expressions.html" title="5.5. Expressions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.4. Patterns</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="parser.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Internals</th><td width="20%" align="right"> <a accesskey="n" href="internals_expressions.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="internals_patterns"></a>5.4. Patterns</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="internals_mem_patterns"></a>5.4.1. Reducing memory usage</h3></div><div><div class="author"><h3 class="author"><span class="firstname">Yvo</span> <span class="surname">Smellenbergh</span></h3></div></div></div><div></div></div><p>
MegaPOV introduces a new patch named 'LESS_MEMORY_IN_PATTERNS_PATCH' to
reduce the amount of memory needed for each pattern.
This is done by replacing the structs in the union <i class="parameter"><tt>Vals</tt></i> by pointers.
The original size of <i class="parameter"><tt>Vals</tt></i> was about 104 bytes, occupied by the crackle pattern.
</p><p>
By using pointers, the size is reduced to 4 bytes plus the size of the data required
for a specific pattern.
If for example Function pattern is used, the size of <i class="parameter"><tt>Vals</tt></i> is 4 plus the size for the
2 pointers which is 8.
This total of 12 is a whole lot less than the original 104!
This patch will increase the amount of memory used if only crackle is used. However,
this is unlikely to happen.
</p><div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="adding_patterns"></a>5.4.1.1. Adding new patterns</h4></div></div><div></div></div><p>
Because MegaPOV is designed to turn on and off each patch separately, you must be
careful whenever a patch is added.
This patch changes many parts of the code and especially the definition of
<i class="parameter"><tt>TPATTERN_FIELDS</tt></i> is a bit tricky.
For example, the ANGLE_OF_INCIDENCE_PATCH is added to the <i class="parameter"><tt>TPATTERN_FIELDS
</tt></i> definition like this in <tt class="filename">frame.h</tt>.
First you define it like this:
</p><pre class="programlisting">#ifdef ANGLE_OF_INCIDENCE_PATCH
#ifdef LESS_MEMORY_IN_PATTERNS_PATCH
typedef struct { VECTOR AOI_origin; unsigned char pt_fixed;
}AOI, *AOIPTR ;
#define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> AOIPTR Aoi;
#else
#define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i> struct { VECTOR AOI_origin; unsigned char pt_fixed; } Aoi;
#endif
#else //ANGLE_OF_INCIDENCE_PATCH
#define <i class="parameter"><tt>AngleOfIncidenceDef</tt></i>
#endif</pre><p>
and then add it to the <i class="parameter"><tt>TPATTERN_FIELDS</tt></i> definition like this:
</p><pre class="programlisting">#define <i class="parameter"><tt>TPATTERN_FIELDS</tt></i> \
unsigned short Type, Wave_Type, Flags; \
: \
union { \
DENSITY_FILE *Density_File; \
: \
<i class="parameter"><tt>AngleOfIncidenceDef</tt></i> \
: \
ProjectionDef \
} Vals;</pre><p>
<i class="parameter"><tt>AngleOfIncidenceDef</tt></i> is always defined to avoid two definitions
for <i class="parameter"><tt>TPATTERN_FIELDS</tt></i>.
If ANGLE_OF_INCIDENCE_PATCH isn't defined, <i class="parameter"><tt>AngleOfIncidenceDef</tt></i>
is empty and is ignored, if ANGLE_OF_INCIDENCE_PATCH is defined, <i class="parameter"><tt>AngleOfIncidenceDef
</tt></i> is a pointer or a struct, depending on whether LESS_MEMORY_IN_PATTERNS_PATCH is
defined or not.
</p><p>
This leaves us with the problem of accessing the members of the members of <i class="parameter"><tt>Vals</tt></i>.
In <tt class="filename">frame.h</tt> LESS_MEMORY_PATCH_MO is defined like this:
</p><pre class="programlisting">#ifdef LESS_MEMORY_IN_PATTERNS_PATCH
#define LESS_MEMORY_PATCH_MO ->
#else
#define LESS_MEMORY_PATCH_MO .
#endif</pre><p>
Whenever you access a member from an element of <i class="parameter"><tt>Vals</tt></i> you use
</p><pre class="programlisting">New->Vals.Crackle LESS_MEMORY_PATCH_MO lastseed = 0x8000000;</pre><p>
which results in
</p><pre class="programlisting">New->Vals.Crackle.lastseed = 0x8000000;
or
New->Vals.Crackle->lastseed = 0x8000000;</pre><p>
depending on the state of the switch LESS_MEMORY_IN_PATTERNS_PATCH.
</p><p>
For each pattern added, which uses a pointer, memory is allocated in the following functions:
</p><div class="itemizedlist"><ul type="disc" compact><li><tt class="filename">parstxtr.cpp</tt> - Parse_Pattern();</li><li><tt class="filename">pattern.cpp</tt> - Copy_TPat_Fields();</li></ul></div><p>
Memory is freed for each new pattern in:
</p><div class="itemizedlist"><ul type="disc" compact><li><tt class="filename">pattern.cpp</tt> - Destroy_TPat_Fields();</li></ul></div><p>
The best way to find all necessary changes is to find all occurrences of one patch and take a look on how
it is implemented.
</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="parser.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="internals.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="internals_expressions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.3. Parser </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.5. Expressions</td></tr></table></div></body></html>
See more files for this project here