Redirecting stdin/stdout to/from command from/to string

Hi,
I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results:
system("nasm -f elf program.asm > output");
The problem is I have to do this process (generate code and execute) a lot of times each time i run my program which slows the execution time due to so much file I/O.

Is there some shell trick by which I can generate my code in a string buffer (instead of the file program.asm) and pass it as input to nasm.
Similarly, can I capture the output of nasm into another string buffer without writing it to a file.

Same applies for compiling c programs using gcc. Can my c program be present in a string which i then compile using gcc by redirecting its input from a file to the string. Likewise, can i redirect the output of my c program to a string instead of stdout or any other file before.

Perhaps using a tmpfs based filesystem would improve the performance enough.

Thanks for the reply but I don't have that option.

Anyways, I found a way to redirect stdout to a string. Its at Get from stdout a string - GIDForums
This method uses pipes. Haven't tried it yet but seems it will work.

Any similar ideas for taking input from a string or some memory buffer instead of files??

What OS are you running that doesn't support a memory backed filesystem ?

The most similar way would be using pipes for input too.

Well, sorry but I don't know anything about tmpfs. So I said I don't have that option.
How can I use it ? I am using ubuntu 9.04.

---------- Post updated at 10:56 AM ---------- Previous update was at 10:56 AM ----------

Google first hit: Create turbocharged storage using tmpfs