Notifications
Clear all

[Closed] Reading ascii files?

 PEN

So I do this all the time using the FileStream Methods. I have never used the memStream Interface. Is one faster then the other? I gather when using memStream it is loading it all into memory which I would think is faster to read from. Has any one done any tests at to which is faster.

One method provides different functions, I can convert what is returned to a stringStream and still run those functions or open strings in the memManager and access them when needed. Just wondering what others might be doing with large ascii files?

6 Replies

I can’t say much about the differences between the two, but I’ve had some problems with memStream manager in the past (I think max 7 or 8). I used it to read in a pretty big ascii files, and it worked 50% of the time (using the exact same script/ascii file). It would either run without any problems, or generate an “unknown exception” error. In case of the latter, max would often crash not long after. I thought it simply ran out of memory but I still had plenty left. After a couple of hours of debugging I gave up and haven’t used the function since. I did notice however that the memStream manager was much faster than the traditional file functions.

This was one or two max versions back though, so the function might have been improved since.

Hope that helps,
Martijn

I currently copy to the systemp for large txt files I read or write. I’ve noticed about a 10% speed increase by copying the file local first, but our servers are pretty overworked. I’ve seen writes that are bad after max returns a succesful write. Once again I believe it is the overtaxed network/servers I need to contend with.
That’s my current work around.

Keith Morrison
focus360.com

I get the same troubles with large files (2M) with max 9 (on vista).

 PEN

Hmm, so memStream is faster but unstable…I think that I will stick with what I have for the moment then. Thanks for the heads up guys.

Hi Paul,

I’d noticed you use the FileStream Method in your attribute holder modifier. I have currently been using an ini file to write and record keys for a script im writing. Is this wrong or does it depend on what you are storing? i can see the limitations of the ini storage method in some ways. I guess you can use a custom filetype with the FileStream Method. Should i be thinking in these terms too, just in case im looking to store more complicated data in future?

 PEN

Yes you need to use a custom file type really. XML is a good choice if you are wanting hierarchal data and that is what I’m working on. There is one built into Max but damned if I could sort it out so I have written my own. XML gives you the ability to wrap data in tags and store it in a very organized way.

For PEN Attribute holder I just used a simple CSV file format I think. It has been a while since I looked at it actualy but I think that is what it was. CSV stands for Common Seperated Value. Each line represents a chunk of data or you can think of it as a row of data in a spread sheet.

PEN Attribute Holder will get a major update at some point and the file format will change I think. I want to be able to store the poses by rollout and in layers of sorts. I will move to the XML formated file for this.

Here is a test for you to run on writting and reading a file.


 --Create path and file name
 filePath=(getDir #scripts)
 fileName="myTestFile.csv"
 theFile=filePath+"\\"+fileName
 
 /**********************************************************
 Funtion for writting an array of data to one line in the file. 
 ********************************************************/
 fn writeData f dataAr=
 (
 	if not (doesFileExist f) then
 	(
 		newF=createFile f
 		close newF
 	)
 	if doesFileExist f then
 	(
 		openF=openFile f mode:"a"
 		for i = 1 to dataAr.count do
 		(
 			format "%" dataAr[i] to:openF
 			if i<dataAr.count then format "," to:openF
 		)
 		format "
" to:openF
 		close openF
 	)
 )
 
 /*******************************************************
 Function for reading data from file. 
 Returns an array. Each element in the array is an array and the
 	nested array are seperated by the comma
 ********************************************************/
 fn readData f=
 (
 	dataAr=#()
 	if doesFileExist f then
 	(
 		openF=openFile f mode:"r"
 		while not (eOf openF) do
 		(
 			append dataAr (filterString (readLine openF) ",")
 		)
 		close openF
 	)
 	dataAr
 )
 
 /*******************************************************
 Collects objects and their parameters as strings to an array
 	and stores them in the final array that is passed out of the function. 
 ********************************************************/
 fn getSceneData=
 (
 	dataAr=#()
 	for o in objects do
 	(
 		oData=#()
 		append oData ("obj:"+o.name)
 		pNames=getPropNames o
 		for p in pNames do
 		(
 			pVal=getProperty o p
 			append oData ((p as string)+":"+(pVal as string))
 		)
 		append dataAr oData
 	)
 	dataAr
 )
 
 
 --Collect the scene data and then write it to the file
 sceneData=getSceneData()
 for sd in sceneData do
 (
 	writeData theFile sd
 )
 
 --Read the data from the file and format it to the listener. 
 fileData=readData theFile
 for fd in fileData do
 (
 	format "%
" fd
 )
 
 / Test Area ***
 doesFileExist theFile
 edit theFile
 deleteFile theFile
 */