*** empty log message ***
This commit is contained in:
		
							parent
							
								
									33c17f4f2f
								
							
						
					
					
						commit
						1b602fe7a2
					
				
							
								
								
									
										22
									
								
								auxstorage.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								auxstorage.h
									
									
									
									
									
								
							| @ -11,16 +11,20 @@ | ||||
| #include <fcntl.h> | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| //CAUTION:
 | ||||
| //it will not work if T is itself a class with dynamically allocated components
 | ||||
| //it cannot be implemented for SparseMat, which lacks fixed record length
 | ||||
| 
 | ||||
| 
 | ||||
| template<typename T> | ||||
| class AuxStorage | ||||
| 	{ | ||||
| 	char filename[16]; | ||||
| 	char filename[32]; | ||||
| 	int fd; | ||||
| 	off64_t recl; | ||||
| 	size_t recl; | ||||
| public: | ||||
| 	AuxStorage(void); | ||||
| 	~AuxStorage(void) {close(fd);}; | ||||
| 	~AuxStorage(void) {close(fd); unlink(filename);}; | ||||
| 	void get(NRVec<T> &x, const int pos) const; | ||||
| 	void put(const NRVec<T> &x, const int pos); | ||||
|         void get(NRMat<T> &x, const int pos) const; | ||||
| @ -32,10 +36,10 @@ public: | ||||
| template<typename T> | ||||
| AuxStorage<T>::AuxStorage(void) | ||||
| { | ||||
| strcpy(filename,"AuxStorageXXXXXX");  | ||||
| strcpy(filename,"AUX_XXXXXX");  | ||||
| mktemp(filename);  | ||||
| unlink(filename); | ||||
| fd=open(filename,O_CREAT|O_LARGEFILE); | ||||
| fd=open(filename,O_CREAT|O_LARGEFILE|O_RDWR,0777); | ||||
| if(fd<0) {perror(""); laerror("open failed in AuxStorage");} | ||||
| recl=0; | ||||
| } | ||||
| @ -44,16 +48,16 @@ template<typename T> | ||||
| void AuxStorage<T>::get(NRVec<T> &x, const int pos) const | ||||
| { | ||||
| if(recl==0) laerror("get from an empty file in AuxStorage"); | ||||
| if((off64_t)-1 == lseek64(fd,pos*recl,SEEK_SET)) {perror(""); laerror("seek failed in AuxStorage");} | ||||
| if(recl!=read(fd,&x[0],recl)) {perror(""); laerror("read failed in AuxStorage");} | ||||
| if((off64_t)-1 == lseek64(fd,pos*((off64_t)recl),SEEK_SET)) {perror(""); laerror("seek failed in AuxStorage");} | ||||
| if((ssize_t)recl!=read(fd,&x[0],recl)) {perror(""); laerror("read failed in AuxStorage");} | ||||
| } | ||||
| 
 | ||||
| template<typename T> | ||||
| void AuxStorage<T>::put(const NRVec<T> &x, const int pos) const | ||||
| void AuxStorage<T>::put(const NRVec<T> &x, const int pos) | ||||
| { | ||||
| if(recl) {if(recl!=x.size()*sizeof(T)) laerror("attempt to write objects of different size to one AuxStorage");} | ||||
| else recl=x.size()*sizeof(T); | ||||
| if((off64_t)-1 == lseek64(fd,pos*recl,SEEK_SET)) {perror(""); laerror("seek failed in AuxStorage");} | ||||
| if((off64_t)-1 == lseek64(fd,pos*((off64_t)recl),SEEK_SET)) {perror(""); laerror("seek failed in AuxStorage");} | ||||
| if(0>write(fd,&x[0],recl)) {perror(""); laerror("write failed in AuxStorage");} | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user