Exemplo n.º 1
0
void testStringBubbleSort(char *filename) {
  int length;
  char **plaetzchenListe;

  plaetzchenListe = readRezeptListe(filename);
  length = getArrayLength(plaetzchenListe);
  printf("---- testStringBubbleSort() -----------------\n\n");
  printf("Es sind %i Rezepte in der Liste\n", length);

  stringBubbleSort(length, plaetzchenListe);

  printStringArray(getArrayLength(plaetzchenListe), plaetzchenListe);

  cleanup(plaetzchenListe); // memory leaks vermeiden -- hier zwar nicht
                            // notwendig aber sinnvoll!
}
Exemplo n.º 2
0
/*
P1 e)
Aufräumarbeiten
*/
void cleanup(char **stringArray) {
  int n = getArrayLength(stringArray);
  for (int i = 0; i < n; i++) {
    free(*(stringArray + i));
  }
  free(stringArray);
}
Exemplo n.º 3
0
// From IXmlSource
void CTypeElement::toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const
{
    if (!isScalar()) {

        xmlElement.setAttribute("ArrayLength", getArrayLength());
    }

    base::toXml(xmlElement, serializingContext);
}
Exemplo n.º 4
0
void MetaModelicaArrayValue::retrieveChildren()
{
  GDBAdapter *pGDBAdapter = GDBAdapter::instance();
  for (int i = 1 ; i <= getArrayLength() ; i++) {
    StackFramesWidget *pStackFramesWidget = MainWindow::instance()->getStackFramesWidget();
    QByteArray cmd = CommandFactory::getMetaTypeElement(pStackFramesWidget->getSelectedThread(), pStackFramesWidget->getSelectedFrame(),
                                                        mpLocalsTreeItem->getName(), i, CommandFactory::array_metaType);
    pGDBAdapter->postCommand(cmd, GDBAdapter::BlockUntilResponse, mpLocalsTreeItem, &GDBAdapter::getMetaTypeElementCB);
  }
}
Exemplo n.º 5
0
// Private methods
void MeetAndroid::processCommand(){
	if(buffer[0]-FunctionBufferOffset < FunctionBufferLenght){
		void (*H_FuncPtr)(uint8_t, uint8_t) = intFunc[buffer[0]-FunctionBufferOffset];
		if (H_FuncPtr != 0) {
			H_FuncPtr(buffer[0], getArrayLength());
		}
		else {
			send("Flag not registered: ");
			send(buffer[0]);
		}
	}
	else {
		if (customErrorFunc)
			errorFunc(buffer[0], getArrayLength());
		else {
			send("Flag out of bounds: ");
			send(buffer[0]);
		}
	}
}
Exemplo n.º 6
0
/**
 * Creates an object in the embedded JVM whose contents are initialized from a given object in Squawk memory.
 * This routine only handles Strings, byte arrays, char arrays and int arrays.
 *
 * @param object  the address of an object in Squawk memory
 * @param fill    true if the return object should be initialized from the Squawk object
 * @return the corresponding object in the embedded JVM
 */
static Address createJVMObject(Address object, boolean fill) {
    if (object != 0) {
        Address cls = getClass(object);
        int id = com_sun_squawk_Klass_id(cls);
        Address jvmObject;
        if (id == CID_STRING || id == CID_STRING_OF_BYTES) {
            jvmObject = createJVMString(object, id, getArrayLength(object));
        } else if (id == CID_BYTE_ARRAY) {
            jvmObject = createJVMByteArray(object, getArrayLength(object), fill);
        } else if (id == CID_CHAR_ARRAY) {
            jvmObject = createJVMCharArray(object, getArrayLength(object), fill);
        } else if (id == CID_INT_ARRAY) {
            jvmObject = createJVMIntArray(object, getArrayLength(object), fill);
        } else {
            fatalVMError("createJVMObject:: Invalid reference type");
        }
        return jvmObject;
    }
    return null;
}
Exemplo n.º 7
0
int main(int argc, const char *argv[])
{

    int len = getArrayLength(14, 5, 3);
    unsigned int *array = getArrayPointer(14, 5, 3);
    printf("ArrayLength: %u\n", len);

    int i;
    for (i = 0; i < len; i += 2) {
        printf("0x%03X 0x%08X\n", array[i], array[i+1]);
    }
    
    return 0;
}
Exemplo n.º 8
0
void testHeap()
{

	int length = getArrayLength();
	MyHeap<int> heap;
	heap.makeMinHeap(arrayList, length);
	cout << "make MinHeap : \t";
	coutList(arrayList, length);

	cout << "sort result : \t";
	heap.heapMinSort(arrayList, length);
	coutList(arrayList, length);

}
Exemplo n.º 9
0
//²âÊÔÁ´±í
void testLinkList()
{
	
	LinkNode<int> *head = new LinkNode<int>();
	MyLinkList<int> link(head);
	for (int i = 0; i < getArrayLength(); i++){
		if (i == 0)
		{
			head->data = &arrayList[i];
			continue;
		}
		link.insertData(link.getFoot(), &arrayList[i]);
	}
	
	cout << "cout linklistData "<<endl;
	link.countLink();
	cout << "length " << link.getLength()<<endl;
	cout << "mid node :  " << *(link.getMidNode()->data)<<endl;
}
Exemplo n.º 10
0
void getSimpleLink(LinkNode<int> *head,bool hasCircle)
{
	
	static MyLinkList<int> link(head);
	for (int i = 0; i < getArrayLength(); i++){
		if (i == 0)
		{
			head->data = &arrayList[i];
			continue;
		}
		link.insertData(link.getFoot(), &arrayList[i]);
	}
	if (hasCircle)
	{
		link.getFoot()->next = link.getNode(4);
	}
//	link.countLink();

}
Exemplo n.º 11
0
unsigned int *getArrayPointer(int board, int bus, int support) { 
    unsigned int hex = 0;
    hex += board;
    hex += bus << 8;
    hex += support << 16;
    hex += 0xFF000000;

    printf("\n\n0x%X\n", hex);

    int i = 0;
    int len = getArrayLength(board, bus, support);
    while (PHY_REG_1TArray[i] != hex && i < len)
        i++;
    i += 2; // skip keywords like 0xABCD

    int j = 0;
    unsigned int *ptr_array = (unsigned int*)malloc(sizeof(int) * len);
    for (i; i < len; i += 2) {
        const unsigned int v1 = PHY_REG_1TArray[i];
        const unsigned int v2 = PHY_REG_1TArray[i+1];


        if (v2 != 0xABCD &&
            v2 != 0xCDEF &&
            v2 != 0xCDCD &&
            v2 != 0xDEAD ) { 
            ptr_array[j++] = v1;
            ptr_array[j++] = v2;
        } else {
            break;
        }
    }
    array_length = j - 1;

    return ptr_array;
}
Exemplo n.º 12
0
/*!
	@brief Clone
*/
OId VariableArrayCursor::clone(TransactionContext &txn,
	const AllocateStrategy &allocateStrategy, OId neighborOId) {
	if (UNDEF_OID == getBaseOId()) {
		return UNDEF_OID;
	}
	OId currentNeighborOId = neighborOId;
	OId linkOId = UNDEF_OID;

	uint32_t srcDataLength = getArrayLength();
	if (srcDataLength == 0) {
		uint8_t *srcObj = getBaseAddr();
		Size_t srcObjSize = getObjectManager()->getSize(srcObj);
		BaseObject destObject(txn.getPartitionId(), *getObjectManager());
		OId destOId = UNDEF_OID;
		if (currentNeighborOId != UNDEF_OID) {
			destObject.allocateNeighbor<uint8_t>(srcObjSize, allocateStrategy,
				destOId, currentNeighborOId, OBJECT_TYPE_VARIANT);
		}
		else {
			destObject.allocate<uint8_t>(
				srcObjSize, allocateStrategy, destOId, OBJECT_TYPE_VARIANT);
		}
		memcpy(destObject.getBaseAddr(), srcObj, srcObjSize);
		linkOId = destOId;
	}
	else {
		OId srcOId = UNDEF_OID;
		OId destOId = UNDEF_OID;
		OId prevOId = UNDEF_OID;
		uint8_t *srcObj = NULL;
		BaseObject destObject(txn.getPartitionId(), *getObjectManager());

		uint8_t *srcElem;
		uint32_t srcElemSize;
		uint32_t srcCount;
		uint8_t *lastElem = NULL;
		uint32_t lastElemSize = 0;
		while (nextElement()) {
			srcObj = data();
			srcOId = getElementOId();
			srcElem = getElement(srcElemSize, srcCount);
			if (srcOId != prevOId) {
				Size_t srcObjSize = getObjectManager()->getSize(srcObj);
				if (currentNeighborOId != UNDEF_OID) {
					destObject.allocateNeighbor<uint8_t>(srcObjSize,
						allocateStrategy, destOId, currentNeighborOId,
						OBJECT_TYPE_VARIANT);
				}
				else {
					destObject.allocate<uint8_t>(srcObjSize, allocateStrategy,
						destOId, OBJECT_TYPE_VARIANT);
				}
				currentNeighborOId =
					destOId;  

				memcpy(destObject.getBaseAddr(), srcObj, srcObjSize);
				if (UNDEF_OID == linkOId) {
					linkOId = destOId;
				}
				else {
					assert(lastElem > 0);
					uint8_t *linkOIdAddr =
						lastElem + lastElemSize +
						ValueProcessor::getEncodedVarSize(lastElemSize);
					uint64_t encodedOId =
						ValueProcessor::encodeVarSizeOId(destOId);
					memcpy(linkOIdAddr, &encodedOId, sizeof(uint64_t));
				}
				prevOId = srcOId;
			}
			lastElem = destObject.getBaseAddr() + (srcElem - srcObj);
			lastElemSize = srcElemSize;
		}
	}
	return linkOId;
}
Exemplo n.º 13
0
/* dfsMarkByMode (s, r, m, shc, slw)
 *
 * Sets all the mark bits in the object graph pointed to by r.
 *
 * If m is MARK_MODE, it sets the bits to 1.
 * If m is UNMARK_MODE, it sets the bits to 0.
 *
 * If shc, it hash-conses the objects marked.
 *
 * If slw, it links the weak objects marked.
 *
 * It returns the total size in bytes of the objects marked.
 */
size_t dfsMarkByMode (GC_state s, pointer root,
                      GC_markMode mode,
                      bool shouldHashCons,
                      bool shouldLinkWeaks) {
  GC_header mark; /* Used to set or clear the mark bit. */
  size_t size; /* Total number of bytes marked. */
  pointer cur; /* The current object being marked. */
  pointer prev; /* The previous object on the mark stack. */
  pointer next; /* The next object to mark. */
  pointer todo; /* A pointer to the pointer in cur to next. */
  GC_header header;
  GC_header* headerp;
  uint16_t bytesNonObjptrs;
  uint16_t numObjptrs;
  GC_objectTypeTag tag;
  uint32_t objptrIndex; /* The i'th pointer in the object (element) being marked. */
  GC_header nextHeader;
  GC_header* nextHeaderp;
  GC_arrayCounter arrayIndex;
  pointer top; /* The top of the next stack frame to mark. */
  GC_returnAddress returnAddress;
  GC_frameLayout frameLayout;
  GC_frameOffsets frameOffsets;

  if (isPointerMarkedByMode (root, mode))
    /* Object has already been marked. */
    return 0;
  mark = (MARK_MODE == mode) ? MARK_MASK : 0;
  size = 0;
  cur = root;
  prev = NULL;
  headerp = getHeaderp (cur);
  header = *headerp;
  goto mark;
markNext:
  /* cur is the object that was being marked.
   * prev is the mark stack.
   * next is the unmarked object to be marked.
   * nextHeaderp points to the header of next.
   * nextHeader is the header of next.
   * todo is a pointer to the pointer inside cur that points to next.
   */
  if (DEBUG_DFS_MARK)
    fprintf (stderr,
             "markNext"
             "  cur = "FMTPTR"  next = "FMTPTR
             "  prev = "FMTPTR"  todo = "FMTPTR"\n",
             (uintptr_t)cur, (uintptr_t)next,
             (uintptr_t)prev, (uintptr_t)todo);
  assert (not isPointerMarkedByMode (next, mode));
  assert (nextHeaderp == getHeaderp (next));
  assert (nextHeader == getHeader (next));
  // assert (*(pointer*) todo == next);
  assert (fetchObjptrToPointer (todo, s->heap.start) == next);
  headerp = nextHeaderp;
  header = nextHeader;
  // *(pointer*)todo = prev;
  storeObjptrFromPointer (todo, prev, s->heap.start);
  prev = cur;
  cur = next;
mark:
  if (DEBUG_DFS_MARK)
    fprintf (stderr, "mark  cur = "FMTPTR"  prev = "FMTPTR"  mode = %s\n",
             (uintptr_t)cur, (uintptr_t)prev,
             (mode == MARK_MODE) ? "mark" : "unmark");
  /* cur is the object to mark.
   * prev is the mark stack.
   * headerp points to the header of cur.
   * header is the header of cur.
   */
  assert (not isPointerMarkedByMode (cur, mode));
  assert (header == getHeader (cur));
  assert (headerp == getHeaderp (cur));
  header ^= MARK_MASK;
  /* Store the mark.  In the case of an object that contains a pointer to
   * itself, it is essential that we store the marked header before marking
   * the internal pointers (markInNormal below).  If we didn't, then we
   * would see the object as unmarked and traverse it again.
   */
  *headerp = header;
  splitHeader (s, header, &tag, NULL, &bytesNonObjptrs, &numObjptrs);
  if (NORMAL_TAG == tag) {
    size +=
      GC_NORMAL_HEADER_SIZE
      + bytesNonObjptrs
      + (numObjptrs * OBJPTR_SIZE);
    if (0 == numObjptrs) {
      /* There is nothing to mark. */
normalDone:
      if (shouldHashCons)
        cur = hashConsPointer (s, cur, TRUE);
      goto ret;
    }
    todo = cur + bytesNonObjptrs;
    objptrIndex = 0;
markInNormal:
    if (DEBUG_DFS_MARK)
      fprintf (stderr, "markInNormal  objptrIndex = %"PRIu32"\n", objptrIndex);
    assert (objptrIndex < numObjptrs);
    // next = *(pointer*)todo;
    next = fetchObjptrToPointer (todo, s->heap.start);
    if (not isPointer (next)) {
markNextInNormal:
      assert (objptrIndex < numObjptrs);
      objptrIndex++;
      if (objptrIndex == numObjptrs) {
        /* Done.  Clear out the counters and return. */
        *headerp = header & ~COUNTER_MASK;
        goto normalDone;
      }
      todo += OBJPTR_SIZE;
      goto markInNormal;
    }
    nextHeaderp = getHeaderp (next);
    nextHeader = *nextHeaderp;
    if (mark == (nextHeader & MARK_MASK)) {
      if (shouldHashCons)
        shareObjptr (s, (objptr*)todo);
      goto markNextInNormal;
    }
    *headerp = (header & ~COUNTER_MASK) | (objptrIndex << COUNTER_SHIFT);
    goto markNext;
  } else if (WEAK_TAG == tag) {
    /* Store the marked header and don't follow any pointers. */
    if (shouldLinkWeaks) {
      GC_weak w;

      w = (GC_weak)(cur + offsetofWeak (s));
      if (DEBUG_WEAK)
        fprintf (stderr, "marking weak "FMTPTR" ",
                 (uintptr_t)w);
      if (isObjptr (w->objptr)) {
        if (DEBUG_WEAK)
          fprintf (stderr, "linking\n");
        w->link = s->weaks;
        s->weaks = w;
      } else {
        if (DEBUG_WEAK)
          fprintf (stderr, "not linking\n");
      }
    }
    goto ret;
  } else if (ARRAY_TAG == tag) {
    /* When marking arrays:
     *   arrayIndex is the index of the element to mark.
     *   cur is the pointer to the array.
     *   objptrIndex is the index of the pointer within the element
     *     (i.e. the i'th pointer is at index i).
     *   todo is the start of the element.
     */
    size +=
      GC_ARRAY_HEADER_SIZE
      + sizeofArrayNoHeader (s, getArrayLength (cur), bytesNonObjptrs, numObjptrs);
    if (0 == numObjptrs or 0 == getArrayLength (cur)) {
      /* There is nothing to mark. */
arrayDone:
      if (shouldHashCons)
        cur = hashConsPointer (s, cur, TRUE);
      goto ret;
    }
    /* Begin marking first element. */
    arrayIndex = 0;
    todo = cur;
markArrayElt:
    assert (arrayIndex < getArrayLength (cur));
    objptrIndex = 0;
    /* Skip to the first pointer. */
    todo += bytesNonObjptrs;
markInArray:
    if (DEBUG_DFS_MARK)
      fprintf (stderr, "markInArray arrayIndex = %"PRIxARRCTR" objptrIndex = %"PRIu32"\n",
               arrayIndex, objptrIndex);
    assert (arrayIndex < getArrayLength (cur));
    assert (objptrIndex < numObjptrs);
    assert (todo == indexArrayAtObjptrIndex (s, cur, arrayIndex, objptrIndex));
    // next = *(pointer*)todo;
    next = fetchObjptrToPointer (todo, s->heap.start);
    if (not (isPointer(next))) {
markNextInArray:
      assert (arrayIndex < getArrayLength (cur));
      assert (objptrIndex < numObjptrs);
      assert (todo == indexArrayAtObjptrIndex (s, cur, arrayIndex, objptrIndex));
      todo += OBJPTR_SIZE;
      objptrIndex++;
      if (objptrIndex < numObjptrs)
        goto markInArray;
      arrayIndex++;
      if (arrayIndex < getArrayLength (cur))
        goto markArrayElt;
      /* Done.  Clear out the counters and return. */
      *getArrayCounterp (cur) = 0;
      *headerp = header & ~COUNTER_MASK;
      goto arrayDone;
    }
    nextHeaderp = getHeaderp (next);
    nextHeader = *nextHeaderp;
    if (mark == (nextHeader & MARK_MASK)) {
      if (shouldHashCons)
        shareObjptr (s, (objptr*)todo);
      goto markNextInArray;
    }
    /* Recur and mark next. */
    *getArrayCounterp (cur) = arrayIndex;
    *headerp = (header & ~COUNTER_MASK) | (objptrIndex << COUNTER_SHIFT);
    goto markNext;
  } else {
    assert (STACK_TAG == tag);
    size +=
      GC_STACK_HEADER_SIZE
      + sizeof (struct GC_stack) + ((GC_stack)cur)->reserved;
    top = getStackTop (s, (GC_stack)cur);
    assert (((GC_stack)cur)->used <= ((GC_stack)cur)->reserved);
markInStack:
    /* Invariant: top points just past the return address of the frame
     * to be marked.
     */
    assert (getStackBottom (s, (GC_stack)cur) <= top);
    if (DEBUG_DFS_MARK)
      fprintf (stderr, "markInStack  top = %"PRIuMAX"\n",
               (uintmax_t)(top - getStackBottom (s, (GC_stack)cur)));
    if (top == getStackBottom (s, (GC_stack)(cur)))
      goto ret;
    objptrIndex = 0;
    returnAddress = *(GC_returnAddress*) (top - GC_RETURNADDRESS_SIZE);
    frameLayout = getFrameLayoutFromReturnAddress (s, returnAddress);
    frameOffsets = frameLayout->offsets;
    ((GC_stack)cur)->markTop = top;
markInFrame:
    if (objptrIndex == frameOffsets [0]) {
      top -= frameLayout->size;
      goto markInStack;
    }
    todo = top - frameLayout->size + frameOffsets [objptrIndex + 1];
    // next = *(pointer*)todo;
    next = fetchObjptrToPointer (todo, s->heap.start);
    if (DEBUG_DFS_MARK)
      fprintf (stderr,
               "    offset %u  todo "FMTPTR"  next = "FMTPTR"\n",
               frameOffsets [objptrIndex + 1],
               (uintptr_t)todo, (uintptr_t)next);
    if (not isPointer (next)) {
      objptrIndex++;
      goto markInFrame;
    }
    nextHeaderp = getHeaderp (next);
    nextHeader = *nextHeaderp;
    if (mark == (nextHeader & MARK_MASK)) {
      objptrIndex++;
      if (shouldHashCons)
        shareObjptr (s, (objptr*)todo);
      goto markInFrame;
    }
    ((GC_stack)cur)->markIndex = objptrIndex;
    goto markNext;
  }
  assert (FALSE);
ret:
  /* Done marking cur, continue with prev.
   * Need to set the pointer in the prev object that pointed to cur
   * to point back to prev, and restore prev.
   */
  if (DEBUG_DFS_MARK)
    fprintf (stderr, "return  cur = "FMTPTR"  prev = "FMTPTR"\n",
             (uintptr_t)cur, (uintptr_t)prev);
  assert (isPointerMarkedByMode (cur, mode));
  if (NULL == prev)
    return size;
  next = cur;
  cur = prev;
  headerp = getHeaderp (cur);
  header = *headerp;
  splitHeader (s, header, &tag, NULL, &bytesNonObjptrs, &numObjptrs);
  /* It's impossible to get a WEAK_TAG here, since we would never
   * follow the weak object pointer.
   */
  assert (WEAK_TAG != tag);
  if (NORMAL_TAG == tag) {
    todo = cur + bytesNonObjptrs;
    objptrIndex = (header & COUNTER_MASK) >> COUNTER_SHIFT;
    todo += objptrIndex * OBJPTR_SIZE;
    // prev = *(pointer*)todo;
    prev = fetchObjptrToPointer (todo, s->heap.start);
    // *(pointer*)todo = next;
    storeObjptrFromPointer (todo, next, s->heap.start);
    if (shouldHashCons)
      markIntergenerationalPointer (s, (pointer*)todo);
    goto markNextInNormal;
  } else if (ARRAY_TAG == tag) {
Exemplo n.º 14
0
QString MetaModelicaArrayValue::getValueString()
{
  return QString("<%1 item%2>").arg(getArrayLength()).arg(getArrayLength() > 1 ? "s" : "");
}
Exemplo n.º 15
0
uintmax_t GC_getArrayLength (pointer a) {
  return ((uintmax_t)(getArrayLength (a)));
}