<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-cite-prefix">On 06/15/2016 09:18 PM, Rajalakshmi
Iyer wrote:<br>
</div>
<blockquote cite="mid:644F3E10-2DED-4672-9221-A0DD3EAC250D@blis.com"
type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<div>Thanks everyone.</div>
<div id="AppleMailSignature"><br>
</div>
<div id="AppleMailSignature">I have been able to compile a C++
module fine. But I am primarily trying to figure out if it's
safe to use features like STL containers or Boost libraries
within an Nginx module.</div>
<div id="AppleMailSignature"><br>
</div>
</blockquote>
In my project, I used STL. it works fine.<br>
<br>
<blockquote cite="mid:644F3E10-2DED-4672-9221-A0DD3EAC250D@blis.com"
type="cite">
<div id="AppleMailSignature">I am asking this because if I try to
allocate an std::string within say the module context, I see a
segmentation fault. I assume it's because of the Nginx pool
mechanism?<br>
<br>
</div>
</blockquote>
<br>
Not sure what is "say the module context", and how you allocate
std::string on Nginx pool. I believe there<br>
are following combinations of "allocating std::string" and
Nginx-pool usage.<br>
<br>
1). does not use pool at all, statement like:<br>
<br>
std::string *p = new std::string("haha"); // instance
allocated from heap<br>
std::string s("haha") // instance allocated from stack.<br>
<br>
<br>
2) use pool to allocate std::string instance, but use heap to
allocate data: like following<br>
<br>
the instance is allocate on pool via placement new, but the
data is allocated from heap.<br>
<br>
void *p = ngx_palloc(enough size)<br>
std::string *s = new(p) std::string("haha")<br>
<br>
it is fine so long as string instance's life time is not
longer than pool<br>
<br>
3). if you want to allocate data on top of ngx pool (for
efficiency reasons), it is bit involved.<br>
first, you need to define an allocation class like this <br>
<a class="moz-txt-link-freetext" href="http://www.mcs.anl.gov/OpenAD/OpenADFortTkExtendedDox/mempool__allocator_8h_source.html">http://www.mcs.anl.gov/OpenAD/OpenADFortTkExtendedDox/mempool__allocator_8h_source.html</a><br>
(NOTE that the MEM_POOL is similar to Nginx pool in many
ways). and feed to allocator<br>
to construction.<br>
<br>
e.g. typedef mempool_allocator<node_type>
my_allocator;<br>
tyepdef std::vector<node_type, my_alloctor>
my_vector_t;<br>
<br>
ngx_pool_t* the_ngx_pool = ....<br>
<br>
my_vector_t vect(myalloctor(the_ngx_pool))<br>
<br>
so the element will allocate from the nginx pool.<br>
<br>
<br>
</body>
</html>