What is happening is that key1 and key2 are not actually the same thing in the same way that &amp;a and &amp;b are not the same thing below.<div>int a = 1;</div><div>int b = 1;<br><div><br></div><div>Thus info-&gt;Has(key1) returns true, info-&gt;Has(key2) returns false, info-&gt;Get(key1) returns the value you stored, and info-&gt;Get(key2) walks off a null pointer and crashes merrily.<div>

<br></div><div>The usage pattern I&#39;ve seen in VTK is to have a static member variable of each particular key that everything sees and uses to get that particular piece of information. See vtkStreamingDemandDrivenPipeline.{h,cxx} REQUEST_UPDATE_EXTENT() and the macros at the bottom of vtkInformationKey.h for example to see it in practice.</div>

<div><br></div><div>By staring really hard at the oxygen, I&#39;ve almost convinced myself that you could also do what you are trying to do by:</div><div>calling vtkInformation CopyEntries() to produce a vtkInformationKeyVectorKey</div>

<div>calling vtkInformationKeyVectorKey::Get(,idx) to return each vtkInformaitonKey</div><div>calling vtkInformation::GetClassName() and GetLocation() to get strings to compare against.</div><div>but I haven&#39;t tried it myself. :)</div>

<div><div><br></div><div>Let us know what you find and please consider adding an example to the vtk examples wiki that demonstrates.</div><div><br clear="all">David E DeMarle<br>Kitware, Inc.<br>R&amp;D Engineer<br>21 Corporate Drive<br>

Clifton Park, NY 12065-8662<br>Phone: 518-881-4909<br>
<br><br><div class="gmail_quote">On Wed, Mar 7, 2012 at 6:00 PM, Alexander Pletzer <span dir="ltr">&lt;<a href="mailto:pletzer@txcorp.com">pletzer@txcorp.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<br>
<br>
The following small code shows how to store and access information by key. The code runs fine but if I comment out line<br>
<br>
// double *vals = info-&gt;Get(key2); // this throws a seg fault....<br>
<br>
then I get a segmentation fault. Here, key2 has the same values as key and therefore I would expect key2 can also be used to access the information. I imagine info to be attached to a vtkDataSet object and key2 to be created in a different location than key, I will not have access to key where I call info-&gt;Get. Thus, I need a mechanism for rebuilding a key from name/location and get back the information attched to this doublet.<br>


<br>
Thanks in advance for any help.<br>
<br>
--Alex<br>
<br>
<br>
// vtk includes<br>
#include &lt;vtkDoubleArray.h&gt;<br>
#include &lt;vtkInformation.h&gt;<br>
#include &lt;<u></u>vtkInformationDoubleVectorKey.<u></u>h&gt;<br>
<br>
// std includes<br>
#include &lt;iostream&gt;<br>
<br>
int main() {<br>
<br>
  // create a 2-element array<br>
  vtkDoubleArray* array = vtkDoubleArray::New();<br>
  array-&gt;SetName(&quot;array&quot;);<br>
  array-&gt;SetNumberOfComponents(<u></u>1);<br>
  array-&gt;SetNumberOfTuples(2);<br>
  array-&gt;SetValue(0, 1.);<br>
  array-&gt;SetValue(1, 2.);<br>
<br>
  // access the info (presently none stored)<br>
  vtkInformation* info = array-&gt;GetInformation();<br>
<br>
  // add one attribute, a double vector<br>
  const char *name = &quot;myKey&quot;;<br>
  const char *location = &quot;MyClass&quot;; //<br>
  const int length = 3;<br>
  vtkInformationDoubleVectorKey *key = new vtkInformationDoubleVectorKey(<u></u>name,<br>
                                                                         location,<br>
                                                                         length);<br>
  vtkInformationDoubleVectorKey *key2 = new vtkInformationDoubleVectorKey(<u></u>name,<br>
                                                                         location,<br>
                                                                         length);<br>
  double values[] = {0.1, 0.2, 0.3};<br>
  info-&gt;Set(key, values[0], values[1],values[2]);<br>
<br>
  // extract the key<br>
  // double *vals = info-&gt;Get(key2); // this throws a seg fault....<br>
<br>
  double *vals = info-&gt;Get(key);<br>
  std::cout &lt;&lt; &quot;extracted values are: &quot; &lt;&lt; vals[0] &lt;&lt; &quot;, &quot; &lt;&lt; vals[1] &lt;&lt; &quot;, &quot; &lt;&lt; vals[2] &lt;&lt; &#39;\n&#39;;<br>
  array-&gt;Delete();<br>
  // array-&gt;Delete will also delete key (do not call delete key)<br>
}<br>
<br>
______________________________<u></u>_________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/<u></u>opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_<u></u>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/<u></u>listinfo/vtkusers</a><br>
</blockquote></div><br></div></div></div></div>