基于指针的数组vs C中的Deque

时间:2019-03-31 23:09:54

标签: c++ pointers java-native-interface deque

我正在用C ++中的SAX解析器解析XML文档。

 <A>
  <B>
   <S i='123'>
   <S i='123'>
   ...
  </B>
 </A>

// C++ code ot represent the above XML in c++
typedef struct {
 UINT32 i;
} S, *PS;

typedef struct {
 PS pointersToS; // Planning to change this to deque.
 UINT32 counter;
} B, *PB;

typedef struct {
 PB pointersToB;
} A, *PA;

旧代码。

PA pointerA = (PA) MEMCALLOC(1,SIZEOF(A));
PB pointerB = (PB) MEMCALLOC(1,SIZEOF(B));
pointerA->pointersToB = pointerB;

PS pointerS = (PS) MEMCALLOC(10,SIZEOF(S));
pointerB.pointersToS = pointerS;

PS pointerS1 = (PS) MEMCALLOC(10,SIZEOF(S));
pointerS1.i=// reading from the xml.

pointerB->pointersToS[counter] = pointerS1;
pointerB.counter++;

PS pointerS2 = (PS) MEMCALLOC(1,SIZEOF(S));
pointerS2.i=// reading from the xml.

pointerB->pointersToS[counter] = pointerS2;
pointerB.counter++;

以上实现效果很好。

现在我要介绍双端队列。

typedef struct {
    UINT32 i;
} S, *PS;

typedef struct {
  std::deque<PS> queueToS;
} B, *PB;

typedef struct {
    PB pointersToB;
} A, *PA;

PA pointerA = (PA) MEMCALLOC(1,SIZEOF(A));
PB pointerB = new PB();
pointerA->pointersToB = pointerB;


PS pointerS1 = (PS) MEMCALLOC(10,SIZEOF(S));
pointerS1.i=// reading from the xml.

pointerB->queueToS.push_back(pointerS1);

PS pointerS2 = (PS) MEMCALLOC(1,SIZEOF(S));
pointerS2.i=// reading from the xml.

pointerB->queueToS.push_back(pointerS2);

我怀疑是由新操作员引起的。尝试从双端队列读取数据时出现错误0x14。 使用双端队列是否合适?我正在cpp层中进行此解析,并将处理程序传递给Java层。当JNI调用来到c ++层以访问其中的数据时,我收到“信号11(SIGSEGV),代码1(SEGV_MAPER),故障加法器0xf4”的错误。

仅在尝试访问队列数据时才出现此错误。我为解析登录名编写了一个单元测试,所有情况都可以正常工作。但是JNI调用会导致错误。

0 个答案:

没有答案