Thread: Buffer

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    1

    Buffer

    Hi,

    I'm a Uni' student from down South. We have an assignment to create a buffer and buffer/unbuffer values for a potentiometer, accelerometer, job stick and buttons from ARM boards the Uni' has recently bought.

    I'm not asking anyone to ANSWER my question; just a little advice for a really stuck student.

    Do I need to define a struct for it, or simply an array? If the latter; do I implement its circular functionality in a method, or?

    How do I implement semaphores and mutex (which are part of the specification)?

    Thanks,

    Dave

  2. #2

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I can't answer a lot of your questions, but there are no methods in C. Structs are used whenever you have a lot of variables, that all are attached to one object (no oop though).

    For instance, a student might have a struct with members of:
    char firstName[30]
    char lastName[32]
    unsigned long int IDNumber
    char major[30]
    float gpa
    int gradeLevel
    char advisor[30]

    so keeping track of lots of students with just separate arrays for each of these variables, would be a PITA, truly. As a struct, it's simple to access whatever you want:
    studs.firstName, etc.

    with the dot member access operator. Then you can make arrays of these structs, and really keep a massive amount of data, right at your fingertips:
    studs[i].firstName, etc.

    In C, a struct is equivalent to a record and a struct member (like firstName), serves as a record field, in some other languages.

    Welcome to the forum, DireStraight, and Good luck with your project.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    An array is adequate if all the elements are of the same data type. For example, "potentiometer, accelerometer, job stick and buttons" may all be numeric, in which case, great!

    You could have an Nx4 array.

    Then you have to decide whether you want FIFO (first-in-first-out) or FILO (first-in-last-out). For your buffer application, you probably want FIFO. One pointer (or index) into the array would keep track of the current/next place to enter new data. The other pointer/index is what is being processed. This lags behind.

    Yes, "circular" sounds like the best approach. The indexes simply wrap back to the beginning once they reach the end. Your buffer needs to have enough elements for worst-case.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  2. Function call from another .c module
    By Ali.B in forum C Programming
    Replies: 14
    Last Post: 08-03-2009, 11:45 AM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM