first-in first-out program

Status
Not open for further replies.
maybe http://www.tenouk.com/ModuleZ.html -- about memory allocation functions
http://www.csd.uoc.gr/~hy534/00a/sec3.html#s34.data_str -- harware implemented but the basic ideas apply also to programmed data structures
http://ciechanowski.me/blog/2014/03/05/exposing-nsmutablearray/ -- educational extending the scope

you better exact at what platform in which environment e.c. and how (what exactly) you need to implement
(usually there is no questions if you have these points set clear to yourself)
 
You're running again... I told you to learn the small stuff first!!
 
small stuff
as function names and syntax

. . . at the i made a major step forward getting started with graphics program though my experience at that time about the particular programming language was near zero -- it's that the step wise achieved output motivated to complete this complex starter project (it's not where you start (not much) but that you do and keep going)
 
[...about.txt] -- a documentation of need to know stuff
for implementing
a stupid javascript fifo [...TEST-1.html] which i doubt does (in a sense of memory allocation) what i think it should (but will do as a poor and impossible for you to grasp example . . . . . . . . . . . . haa , haa , haa , haa )

// tested in Opera and IE for now also MZ.FF -- PS! -- but since it late here , i do not dispose my objects correctly -- as in about.txt -- all data fields of the popped elements must be cleared and their references set to undefined or deleted -- the proper structure/method would be reading all data into some permanent or temporary fetch variable from the element popped from the FiFo then erasing the popped Element ...
 

Attachments

  • jsObjPTR~about.txt
    5.3 KB · Views: 201
  • jsObjPTR-TEST-1.html.txt
    2.9 KB · Views: 229
Last edited:
I often use a fifo to store received characters via serial interrupt.
This is how I implement it in C.
Code:
#include <xc.h>
#include "fifo.h"

#define FifoLength 32
unsigned char FifoBuffer[FifoLength];
unsigned char *FifoStart;
unsigned char *FifoEnd;
unsigned char count;


void InitFifo(void){
    FifoStart=FifoBuffer;
    FifoEnd=FifoBuffer;
    count=0;
}

void PutFifo(unsigned char chr){
    *FifoEnd++=chr;
    count++;
    if(FifoEnd==FifoBuffer+FifoLength)      //reached end
        FifoEnd=FifoBuffer;                 //yes so wrap
    if(count=FifoLength){                   //is head eating tail?
        //fifo full so deal with it!!
    }
}

unsigned char GetFifo(void){
unsigned char chr;
    while(FifoStart==FifoEnd);              //if fifo empty then wait
    chr=*FifoStart++;
    count--;
    if(FifoStart==FifoBuffer+FifoLength)    //wrapped?
        FifoStart=FifoBuffer;               //yes
    return(chr);
}

unsigned char FifoCount(void){
    return(count);
}

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…