[Tex/LaTex] Diagrams package that allows to draw computer buffers (memory diagrams)

diagramspackages

I'm writing a document that explains internals of memory buffers and computers and I'm looking for a LaTeX package that would allow me to create diagrams similar to the following:

Circular buffer:

enter image description here

Linear buffer:

enter image description here

Any suggestions?

Best Answer

You can draw such diagrams with TikZ (tikz package plus libraries) or PS-Tricks (pstricks and other pst- packages). I personally would recommend TikZ.

Here is how I would draw these diagrams:

\documentclass{article}

\usepackage{tikz}

\begin{document}
\sffamily
\textbf{Circular buffer:}

\begin{tikzpicture}[>=latex,font=\sffamily,semithick,scale=1.75]
    \fill [green!25] (0,0) -- (67.5:1) arc [end angle=-22.5, start angle=67.5, radius=1] -- cycle;
    \draw [thick] (0,0) circle (1);
    \foreach \angle in {90,67.5,...,-67.5}
        \draw (\angle:1) -- (\angle-180:1);
    \node [circle,thick,fill=white,draw=black,align=center,minimum size=3cm] at (0,0) {FIFO as a\\Circulate Buffer};
    \draw [<-] (56.25:1) -- (56.25:1.25) -- +(.333,0)
        node [right,inner xsep=.333cm] (Head) {Head (extract)};
    \draw [<-] (-33.75:1) -- (-33.75:1.25) -- +(.333,0)
        node [right,inner xsep=.333cm] (Tail) {Tail (insert)};
    \draw [->,shorten >=5pt,shorten <=5pt] (Tail.west) to [bend right] 
        node [midway,sloped,above,allow upside down] {\footnotesize 4\,bytes in FIFO}
    (Head.west);
\end{tikzpicture}

\bigskip
\bigskip

\textbf{Linear buffer:}
\par
\bigskip

\begin{tikzpicture}[>=latex,font=\sffamily,every node/.style={minimum width=1cm,minimum height=1.5em,outer sep=0pt,draw=black,fill=blue!40,semithick}]
        \node at (0,0) (A) {};
        \node [anchor=west] at (A.east) (B) {};
        \node [anchor=west] at (B.east) (C) {1};
        \node [anchor=west] at (C.east) (D) {2};
        \node [anchor=west] at (D.east) (E) {3};
        \node [anchor=west] at (E.east) (F) {};
        \node [anchor=west] at (F.east) (G) {};
        \draw [->,shorten >=2pt,shorten <=2pt,semithick] (G.south) -- +(0,-1em) -| (A);
\end{tikzpicture}
\end{document}

Result

Related Question