reading from a file with read(... void * buffer...)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > reading from a file with read(... void * buffer...)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    reading from a file with read(... void * buffer...)  
ferbar


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-25-05 10:53 PM

Hi,

I'm writing a program comparing file access patterns. I'm starting with
'read' on a 3MB file.

The function that reads from the file is the following:

void read1test(int fd, void * buffer) {
ssize_t bytesr;

bytesr = read(fd, buffer, BUFFSIZE1);
if (bytesr < 0) {
perror("read:");
exit(bytesr);
}
}

Using Eclipse+CDT, I'm debugging the code, and when the execution is at
the bytesr = read() line, I am not able to see what is stored in the
'buffer' variable.

Below you can see part of the code.

Thanks in advance,

FBM
 ________________________________________
__________________________
#define BUFFSIZE1 1024
#define FOR_READING 0 //(of no use)

#include <fcntl.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

double now(void) {
struct timeval t;
gettimeofday(&t,NULL);
return ((double)t.tv_sec + (double)t.tv_usec/1000000.0);
}

int openRtest(char *pathnameX) {
int fd;
fd = open(pathnameX, O_RDONLY);
if (fd < 0) {
perror("desc:");
exit(fd);
}
return fd;
}

int openWtest(char *pathnameX) {
int fd;
fd = open(pathnameX, O_RDWR|O_CREAT|S_IRUSR|S_IWUSR);
if (fd < 0) {
perror("desc:");
exit(fd);
}
return fd;
}

void read1test(int fd, void * buffer) {
ssize_t bytesr;

bytesr = read(fd, buffer, BUFFSIZE1);
if (bytesr < 0) {
perror("read:");
exit(bytesr);
}
}

void lseek1test(int fd, off_t offset, int lseekaction, void * buffer,
int seekcurr) {
int currpos, nextposition;
ssize_t bytesr;


currpos = lseek(fd, 0, seekcurr);
if (currpos == -1) {
perror("lseek:");
exit(currpos);
}
switch (lseekaction) {
case 0:
while (bytesr != 0) {
bytesr = read(fd, buffer, BUFFSIZE1);
if (bytesr < 0) {
perror("read:");
exit(bytesr);
}
nextposition = lseek(fd, offset, SEEK_CUR);
}
}
}

void write1test(int fd, void *buffer) {

ssize_t bytesw;
size_t nbytes;
bytesw = write(fd, buffer, nbytes);
if (bytesw < 0) {
perror("write:");
exit(bytesw);
}

}
int main(int argc, char** argv) {
int fdo1, fdo2, fdo3, initposition;
double t;
char * pathname1, * pathname2;
void * bufread , * bufread2;
char outputpathname[] = "/tmp/output1.txt";

initposition = 0;

bufread = (void*)malloc(BUFFSIZE1*sizeof(void));
bufread2 = (void*)malloc(BUFFSIZE1*sizeof(void));
pathname1 = argv[1];
pathname2 = argv[2];

/* opening file 1 test	*/
t = now();
fdo1 = openRtest(pathname1);
t = now() - t;
printf("time to open file %s: %.3f\n", pathname1, t);

/* opening file 2 test	*/
t = now();
fdo2 = openRtest(pathname2);
t = now() - t;
printf("time to open file %s: %.3f\n", pathname2, t);


t = now();
read1test(fdo1, bufread);
t = now() - t;
printf("time to read blocksize %d from file %s: %.3f\n", BUFFSIZE1,
pathname1, t);

t = now();
read1test(fdo2, bufread);
t = now() - t;
printf("time to read blocksize %d from file %s: %.3f\n", BUFFSIZE1,
pathname2, t);

(........)






[ Post a follow-up to this message ]



    Re: reading from a file with read(... void * buffer...)  
ferbar


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-25-05 10:53 PM

About post:

I can see the output with printf(buffer)... so, I guess it's not a
problem.. though I don't understand why it doesn't appear in the
debugger..

Anyway, thanks

FBM

ferbar wrote:
> Hi,
>
> I'm writing a program comparing file access patterns. I'm starting with
> 'read' on a 3MB file.
>
> The function that reads from the file is the following:
>
> void read1test(int fd, void * buffer) {
> 	ssize_t bytesr;
>
> 	bytesr = read(fd, buffer, BUFFSIZE1);
> 	if (bytesr < 0) {
> 		perror("read:");
> 		exit(bytesr);
> 	}
> }
>
> Using Eclipse+CDT, I'm debugging the code, and when the execution is at
> the bytesr = read() line, I am not able to see what is stored in the
> 'buffer' variable.
>
> Below you can see part of the code.
>
> Thanks in advance,
>
> FBM
>  ________________________________________
__________________________
> #define BUFFSIZE1 1024
> #define FOR_READING 0 //(of no use)
>
> #include <fcntl.h>
> #include <sys/time.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> double now(void) {
> 	struct timeval t;
> 	gettimeofday(&t,NULL);
> 	return ((double)t.tv_sec + (double)t.tv_usec/1000000.0);
> }
>
> int openRtest(char *pathnameX) {
> 	int fd;
> 	fd = open(pathnameX, O_RDONLY);
> 	if (fd < 0) {
> 		perror("desc:");
> 		exit(fd);
> 	}
> 	return fd;
> }
>
> int openWtest(char *pathnameX) {
> 	int fd;
> 	fd = open(pathnameX, O_RDWR|O_CREAT|S_IRUSR|S_IWUSR);
> 	if (fd < 0) {
> 		perror("desc:");
> 		exit(fd);
> 	}
> 	return fd;
> }
>
> void read1test(int fd, void * buffer) {
> 	ssize_t bytesr;
>
> 	bytesr = read(fd, buffer, BUFFSIZE1);
> 	if (bytesr < 0) {
> 		perror("read:");
> 		exit(bytesr);
> 	}
> }
>
> void lseek1test(int fd, off_t offset, int lseekaction, void * buffer,
> int seekcurr) {
> 	int currpos, nextposition;
> 	ssize_t bytesr;
>
>
> 	currpos = lseek(fd, 0, seekcurr);
> 	if (currpos == -1) {
> 		perror("lseek:");
> 		exit(currpos);
> 	}
> 	switch (lseekaction) {
> 		case 0:
> 			while (bytesr != 0) {
> 				bytesr = read(fd, buffer, BUFFSIZE1);
> 				if (bytesr < 0) {
> 					perror("read:");
> 					exit(bytesr);
> 				}
> 				nextposition = lseek(fd, offset, SEEK_CUR);
> 			}
> 	}
> }
>
> void write1test(int fd, void *buffer) {
>
> 	ssize_t bytesw;
> 	size_t nbytes;
> 	bytesw = write(fd, buffer, nbytes);
> 	if (bytesw < 0) {
> 		perror("write:");
> 		exit(bytesw);
> 	}
>
> }
> int main(int argc, char** argv) {
> 	int fdo1, fdo2, fdo3, initposition;
> 	double t;
> 	char * pathname1, * pathname2;
> 	void * bufread , * bufread2;
> 	char outputpathname[] = "/tmp/output1.txt";
>
> 		initposition = 0;
>
> 		bufread = (void*)malloc(BUFFSIZE1*sizeof(void));
> 		bufread2 = (void*)malloc(BUFFSIZE1*sizeof(void));
> 		pathname1 = argv[1];
> 		pathname2 = argv[2];
>
> 		/* opening file 1 test	*/
> 		t = now();
> 		fdo1 = openRtest(pathname1);
> 		t = now() - t;
> 		printf("time to open file %s: %.3f\n", pathname1, t);
>
> 		/* opening file 2 test	*/
> 		t = now();
> 		fdo2 = openRtest(pathname2);
> 		t = now() - t;
> 		printf("time to open file %s: %.3f\n", pathname2, t);
>
>
> 		t = now();
> 		read1test(fdo1, bufread);
> 		t = now() - t;
> 		printf("time to read blocksize %d from file %s: %.3f\n", BUFFSIZE1,
> pathname1, t);
>
> 		t = now();
> 		read1test(fdo2, bufread);
> 		t = now() - t;
> 		printf("time to read blocksize %d from file %s: %.3f\n", BUFFSIZE1,
> pathname2, t);
>
> (........)






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:33 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register