// this below shows compiler just carries 4 bytes or size of pointer not the whole size of array as argument
int sumOfElements(int A[]){  //compiler sees int* A call by reference st also pass size of array
    int i, sum =0;
    int size = sizeOf(A)/sizeOf(A[0]);  //put this in main method and pass to eumOfElements instead, as another parameter
    for(i=0;i< size;i++ {
       sum+=A[i];
    }
    return sum;
}
Beispiel #2
0
int main	(int argc, char *argv[]) {

    int	id0, id1;
	int i;

    id0 = mcreate(0, func0, (void *)&i);
    id1 = mcreate(1, func1, (void *)&i);

    printf("Eu sou a main após a criação de ID0 e ID1, %d\n", (sizeOf(ready1) + sizeOf(ready0) + sizeOf(ready2) + sizeOf(blockedThreads)));

    mwait(id0);
    mwait(id1);
	
    printf("Eu sou a main voltando para terminar o programa\n");
}
static void * Class_ctor (void * _self, va_list * app)
{	struct Class * self = _self;
	const size_t offset = offsetof(struct Class, ctor);

	self -> name = va_arg(* app, char *);
	self -> super = va_arg(* app, struct Class *);
	self -> size = va_arg(* app, size_t);

	assert(self -> super);

	memcpy((char *) self + offset, (char *) self -> super
					+ offset, sizeOf(self -> super) - offset);
{
	typedef void (* voidf) ();	/* generic function pointer */
	voidf selector;
	va_list ap = * app;

	while ((selector = va_arg(ap, voidf)))
	{	voidf method = va_arg(ap, voidf);

		if (selector == (voidf) ctor)
			* (voidf *) & self -> ctor = method;
		else if (selector == (voidf) dtor)
			* (voidf *) & self -> dtor = method;
		else if (selector == (voidf) differ)
			* (voidf *) & self -> differ = method;
		else if (selector == (voidf) puto)
			* (voidf *) & self -> puto = method;
	}

	return self;
}}
Beispiel #4
0
int main()
{
        void *o = new(Object);
        const void *Any = new(Class,
                              "Any", Object, sizeOf(o),
                              differ, Any_Differ,
                              // maybe more pairs
                              0);

        void *a = new(Any);

        puto(Any, stdout);
        puto(o, stdout);
        puto(a, stdout);

        if(differ(o,o) == differ(a, a))
                puts("ok");

        if(differ(o, a) != differ(a, o))
                puts("not commutative");

        delete(o), delete(a);
        delete((void *)Any);

        return 0;
}
Beispiel #5
0
float median(struct node *root)
{
	int i=1,len=sizeOf(root);
	if(root != NULL)
	{
	for(i=1;i<len/2&&len>2;i++)
		root = root->next;
	return len==1?root->item:len%2==0?(root->item + root->next->item)/2.0:root->next->item;
	}
	else return NULL;
}
Beispiel #6
0
 void compileFunction(Symbol functionDefinitionStatement)
 {
     if (functionDefinitionStatement.cache<FunctionDefinitionCache>()->
         getCompilingFlag()) {
         // TODO: Give more details about what's being evaluated and how that came to call this
         spanOf(functionDefinitionStatement).end().throwError(
             "Function called during its own compilation");
     }
     functionDefinitionStatement.cache<FunctionDefinitionCache>()->
         setCompilingFlag(true);
     _epilogueStack.push(SymbolLabel());
     //Symbol type = typeOf(functionDefinitionStatement);
     //Symbol returnType = type[1].symbol();
     //_returnTypeStack.push(returnType);
     int stackAdjust = offsetOf(functionDefinitionStatement);
     if (stackAdjust != 0)
         addAdjustStackPointer(-stackAdjust);
     _stackOffset = 0;
     compileStatementSequence(functionDefinitionStatement[4].array());
     Symbol type = typeOf(functionDefinitionStatement);
     Symbol returnType = type[1].symbol();
     int returnTypeSize = (sizeOf(returnType) + 3) & -4;
     int parametersSize = 0;
     SymbolArray parameterTypes = type[2].array();
     for (int i = 0; i < parameterTypes.count(); ++i)
         parametersSize += (sizeOf(parameterTypes[i]) + 3) & -4;
     if (_reachable && returnType.atom() != atomVoid) {
         // TODO: Give more details about how it got there
         spanOf(functionDefinitionStatement).end().throwError(
             "Control reaches end of non-Void function");
     }
     addLabel(_epilogueStack.pop());
     addLoadWordFromStackRelativeAddress(returnTypeSize + stackAdjust);
     addMoveBlock(0, stackAdjust + 4 + parametersSize, 1 + returnTypeSize/4);
     if (stackAdjust != 0)
         addAdjustStackPointer(stackAdjust);
     add(Symbol(atomReturn));
     //_returnTypeStack.pop();
     functionDefinitionStatement.cache<FunctionDefinitionCache>()->setCompilingFlag(false);
     functionDefinitionStatement[5].label().setTarget(_firstBasicBlock.target());
 }
Beispiel #7
0
void *func(void *arg){
   printf("Starting func... remaining threads: %d\n", sizeOf(ready1));
   while ( inc < MAX_SIZE ) {
       vetor[inc] = (int)arg;
       inc++;
       if ( (inc % 20) == 0 )
          myield();
       else
           continue;
   }

   return (NULL);
}
Beispiel #8
0
void Box::tupleIndex(int a_linearIndex, int a_tupleIndex[DIM]) const
{
  int size = sizeOf();
  for (int i=DIM-1 ; i >=1 ; i--)
    {
      size = size/(m_highCorner[i] - m_lowCorner[i] + 1);
      int remainder = a_linearIndex%size;
      a_tupleIndex[i] =  (a_linearIndex-remainder)/size + m_lowCorner[i];
      a_linearIndex = remainder;
      
    }
  a_tupleIndex[0] = a_linearIndex + m_lowCorner[0];
}
CPDULoungeHandshake::CPDULoungeHandshake(
                       const char* username,
                       u_int16_t   platform,
                       u_byte_t*   checksum)
  :
  PDUHeader(PDU_LB_Handshake, sizeOf(), NULL, NULL),
  platform_(platform)
{
  if (username != NULL && *username != '\0')
    strncpy(username_, username, PDU_STRINGSIZE);
  else
    memset(username_, 0, sizeof(username_));
  
  memcpy(checksum_, checksum, CLIENT_CHECKSUM_SIZE);
}
Beispiel #10
0
JSArrayBufferView::ConstructionContext::ConstructionContext(
    VM& vm, Structure* structure, uint32_t length, uint32_t elementSize,
    InitializationMode mode)
    : m_structure(0)
    , m_length(length)
    , m_butterfly(0)
{
    if (length <= fastSizeLimit) {
        // Attempt GC allocation.
        void* temp = 0;
        size_t size = sizeOf(length, elementSize);
        // CopiedSpace only allows non-zero size allocations.
        if (size && !vm.heap.tryAllocateStorage(0, size, &temp))
            return;

        m_structure = structure;
        m_vector = temp;
        m_mode = FastTypedArray;

#if USE(JSVALUE32_64)
        if (mode == ZeroFill) {
            uint64_t* asWords = static_cast<uint64_t*>(m_vector);
            for (unsigned i = size / sizeof(uint64_t); i--;)
                asWords[i] = 0;
        }
#endif // USE(JSVALUE32_64)
        
        return;
    }

    // Don't allow a typed array to use more than 2GB.
    if (length > static_cast<unsigned>(INT_MAX) / elementSize)
        return;
    
    if (mode == ZeroFill) {
        if (!tryFastCalloc(length, elementSize).getValue(m_vector))
            return;
    } else {
        if (!tryFastMalloc(length * elementSize).getValue(m_vector))
            return;
    }
    
    vm.heap.reportExtraMemoryCost(static_cast<size_t>(length) * elementSize);
    
    m_structure = structure;
    m_mode = OversizeTypedArray;
}
Beispiel #11
0
int main() {

	void * a = new(String, "aasdfasdfc");
	void * aa = clone(a);
	void * b = new(String, "b");

	printf("sizeOf(a) == %u\n", sizeOf(a));
	if (differ(a, b))
		puts("ok");
	if (differ(a, aa))
		puts("differ?");
	if (a == aa)
		puts("clone?");
	delete(a), delete(aa), delete(b);

	return 0;
}
Beispiel #12
0
PDUPlayerInfo::PDUPlayerInfo(const char* buf)
  :
  PDUHeader   (buf),
  num_players_(0),
  pPlayers_   (0)
{  
  u_int16_t* pint = (u_int16_t*)&buf[PDU_HEADER_SIZE];
  num_players_ = ntohs(*pint++);

  // Rest of the data is PlayerInfos - extract
  // from the buffer
  size_t extraBytes = length_ - sizeOf();
  u_int16_t num_players = extraBytes / sizeof(PlayerInfo);
  PDU_ASSERT(num_players == num_players_);
  num_players_ = num_players;

  if (num_players_ > 0)
    pPlayers_ = new PlayerInfo[num_players_];

  if (pPlayers_)
  { 
    memset(pPlayers_, 0, num_players_ * sizeof(PlayerInfo));
    PlayerInfo* pP = pPlayers_;

    for (int i = 0; i < num_players_; i++, pP++)
    {
      pP->slot_ = ntohs(*pint++);
      
      CChips::chip_amount_t* pchips = (CChips::chip_amount_t*)pint;
      pP->chips_ = *pchips++; // XXX NOTE: in network byte order

      pint = (u_int16_t*)pchips;
      pP->state_ = ntohs(*pint++);
      u_byte_t* pbyte = (u_byte_t*)pint;
      memcpy(pP->username_, pbyte, PDU_STRINGSIZE);
      pbyte += PDU_STRINGSIZE;
      memcpy(pP->city_, pbyte, PDU_STRINGSIZE);
      pbyte += PDU_STRINGSIZE;
      pint = (u_int16_t*)pbyte;
    }
  }      
}
Beispiel #13
0
// @TODO: make cnpy and our wrapper talk to each other in terms of types
// or implement our own saving routines for npz based on npy, probably better.
void saveItemsNpz(const std::string& fileName, const std::vector<Item>& items) {
  std::vector<cnpy::NpzItem> npzItems;
  for(auto& item : items) {
    std::vector<unsigned int> shape(item.shape.begin(), item.shape.end());
    char type;

    if(item.type == Type::float32)
      type = cnpy::map_type(typeid(float));
    else if(item.type == Type::float64)
      type = cnpy::map_type(typeid(double));
    else if(item.type == Type::int8)
      type = cnpy::map_type(typeid(char));
    else
      ABORT("Other types not supported yet");

    npzItems.emplace_back(
        item.name, item.bytes, shape, type, sizeOf(item.type));
  }
  cnpy::npz_save(fileName, npzItems);
}
struct node* noHalfEvenOddValues(struct node *root)
{
	if(root!= NULL)
	{
		int i=1,j=0,n=sizeOf(root);
		struct node *temp = (struct node*)malloc(sizeof(struct node));
		temp = root;
		while(temp!=NULL)
		{
			if(j<n/2)
			{
				if(temp->item%2 == 1 || temp->item%2 == -1)
				{
					temp = temp->next;
					root = deleteAtPosition(i,root);
				}
				else
				{
					i++;
					temp = temp->next;
				}
			}
			else
			{
				if(temp->item%2 == 0)
				{
					temp = temp->next;
					root = deleteAtPosition(i,root);
				}
				else
				{
					i++;
					temp = temp->next;
				}
			}
			j++;
		}
	}
	return root;
}
Beispiel #15
0
status_t WebmWriter::reset() {
    if (mInitCheck != OK) {
        return OK;
    } else {
        if (!mStarted) {
            release();
            return OK;
        }
    }

    status_t err = OK;
    int64_t maxDurationUs = 0;
    int64_t minDurationUs = 0x7fffffffffffffffLL;
    for (int i = 0; i < kMaxStreams; ++i) {
        if (mStreams[i].mThread == NULL) {
            continue;
        }

        status_t status = mStreams[i].mThread->stop();
        if (err == OK && status != OK) {
            err = status;
        }

        int64_t durationUs = mStreams[i].mThread->getDurationUs();
        if (durationUs > maxDurationUs) {
            maxDurationUs = durationUs;
        }
        if (durationUs < minDurationUs) {
            minDurationUs = durationUs;
        }
    }

    if (numTracks() > 1) {
        ALOGD("Duration from tracks range is [%" PRId64 ", %" PRId64 "] us", minDurationUs, maxDurationUs);
    }

    mSinkThread->stop();

    // Do not write out movie header on error.
    if (err != OK) {
        release();
        return err;
    }

    sp<WebmElement> cues = new WebmMaster(kMkvCues, mCuePoints);
    uint64_t cuesSize = cues->totalSize();
    // TRICKY Even when the cues do fit in the space we reserved, if they do not fit
    // perfectly, we still need to check if there is enough "extra space" to write an
    // EBML void element.
    if (cuesSize != mEstimatedCuesSize && cuesSize > mEstimatedCuesSize - kMinEbmlVoidSize) {
        mCuesOffset = ::lseek(mFd, 0, SEEK_CUR);
        cues->write(mFd, cuesSize);
    } else {
        uint64_t spaceSize;
        ::lseek(mFd, mCuesOffset, SEEK_SET);
        cues->write(mFd, cuesSize);
        sp<WebmElement> space = new EbmlVoid(mEstimatedCuesSize - cuesSize);
        space->write(mFd, spaceSize);
    }

    mCuePoints.clear();
    mStreams[kVideoIndex].mSink.clear();
    mStreams[kAudioIndex].mSink.clear();

    uint8_t bary[sizeof(uint64_t)];
    uint64_t totalSize = ::lseek(mFd, 0, SEEK_END);
    uint64_t segmentSize = totalSize - mSegmentDataStart;
    ::lseek(mFd, mSegmentOffset + sizeOf(kMkvSegment), SEEK_SET);
    uint64_t segmentSizeCoded = encodeUnsigned(segmentSize, sizeOf(kMkvUnknownLength));
    serializeCodedUnsigned(segmentSizeCoded, bary);
    ::write(mFd, bary, sizeOf(kMkvUnknownLength));

    uint64_t durationOffset = mInfoOffset + sizeOf(kMkvInfo) + sizeOf(mInfoSize)
        + sizeOf(kMkvSegmentDuration) + sizeOf(sizeof(double));
    sp<WebmElement> duration = new WebmFloat(
            kMkvSegmentDuration,
            (double) (maxDurationUs * 1000 / mTimeCodeScale));
    duration->serializePayload(bary);
    ::lseek(mFd, durationOffset, SEEK_SET);
    ::write(mFd, bary, sizeof(double));

    List<sp<WebmElement> > seekEntries;
    seekEntries.push_back(WebmElement::SeekEntry(kMkvInfo, mInfoOffset - mSegmentDataStart));
    seekEntries.push_back(WebmElement::SeekEntry(kMkvTracks, mTracksOffset - mSegmentDataStart));
    seekEntries.push_back(WebmElement::SeekEntry(kMkvCues, mCuesOffset - mSegmentDataStart));
    sp<WebmElement> seekHead = new WebmMaster(kMkvSeekHead, seekEntries);

    uint64_t metaSeekSize;
    ::lseek(mFd, mSegmentDataStart, SEEK_SET);
    seekHead->write(mFd, metaSeekSize);

    uint64_t spaceSize;
    sp<WebmElement> space = new EbmlVoid(kMaxMetaSeekSize - metaSeekSize);
    space->write(mFd, spaceSize);

    release();
    return err;
}