Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit962a4bb

Browse files
committed
In copy_file, use a palloc'd buffer instead of just a local char array;
a local array isn't guaranteed to have any particular alignment, andso it could slow down the data transfer.
1 parentfad7e8e commit962a4bb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

‎src/port/copydir.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*as a service.
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.12 2005/08/0219:02:32 tgl Exp $
14+
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.13 2005/09/0218:55:32 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -88,11 +88,16 @@ copydir(char *fromdir, char *todir, bool recurse)
8888
staticvoid
8989
copy_file(char*fromfile,char*tofile)
9090
{
91-
charbuffer[8*BLCKSZ];
91+
char*buffer;
9292
intsrcfd;
9393
intdstfd;
9494
intnbytes;
9595

96+
/* Use palloc to ensure we get a maxaligned buffer */
97+
#defineCOPY_BUF_SIZE (8 * BLCKSZ)
98+
99+
buffer=palloc(COPY_BUF_SIZE);
100+
96101
/*
97102
* Open the files
98103
*/
@@ -114,7 +119,7 @@ copy_file(char *fromfile, char *tofile)
114119
*/
115120
for (;;)
116121
{
117-
nbytes=read(srcfd,buffer,sizeof(buffer));
122+
nbytes=read(srcfd,buffer,COPY_BUF_SIZE);
118123
if (nbytes<0)
119124
ereport(ERROR,
120125
(errcode_for_file_access(),
@@ -147,4 +152,6 @@ copy_file(char *fromfile, char *tofile)
147152
errmsg("could not close file \"%s\": %m",tofile)));
148153

149154
close(srcfd);
155+
156+
pfree(buffer);
150157
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp