[Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x
PXA27Xdynqueue.c, 1.1, 1.2
Josh
jsherbach at users.sourceforge.net
Fri Aug 26 13:23:43 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8837
Modified Files:
PXA27Xdynqueue.c
Log Message:
a slight change to save memory (if dequeue causes the number of items
to drop below physical length / 2 - 5, then the queue halves itself)
Index: PXA27Xdynqueue.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/platform/pxa27x/PXA27Xdynqueue.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PXA27Xdynqueue.c 18 Aug 2005 20:36:39 -0000 1.1
--- PXA27Xdynqueue.c 26 Aug 2005 20:23:41 -0000 1.2
***************
*** 106,109 ****
--- 106,130 ----
/*------------------------------------------------------------------*/
+ static void DynQueue_shiftshrink(DynQueue oDynQueue)
+
+ /* Shift the elements to the start of the array
+ and halves the physical length of oDynQueue.*/
+ {
+ //assert(oDynQueue != NULL);
+ if(oDynQueue == NULL)
+ return;
+ //choosing to waste space over wasting time by not always shifting
+ if(oDynQueue->index > 0){
+ memcpy((void *)oDynQueue->ppvQueue, (void *)(oDynQueue->ppvQueue + oDynQueue->index), sizeof(void *) * oDynQueue->iLength);
+ oDynQueue->index = 0;
+ }
+ oDynQueue->iPhysLength /= 2;
+ oDynQueue->ppvQueue = (const void**)realloc(oDynQueue->ppvQueue,
+ sizeof(void*) * oDynQueue->iPhysLength);
+ //assert(oDynQueue->ppvQueue != NULL);
+ }
+
+ /*------------------------------------------------------------------*/
+
void DynQueue_enqueue(DynQueue oDynQueue, const void *pvItem)
/* Adds pvItem to oDynQueue.*/
***************
*** 137,140 ****
--- 158,164 ----
oDynQueue->iLength--;
oDynQueue->index++;
+
+ if(oDynQueue->iLength + 5 < oDynQueue->iPhysLength / 2)
+ DynQueue_shiftshrink(oDynQueue);
return (void*)pvItem;
}
More information about the Tinyos-beta-commits
mailing list