Skip to content

Commit 962a4bb

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, and so it could slow down the data transfer.
1 parent fad7e8e commit 962a4bb

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/02 19:02:32 tgl Exp $
14+
* $PostgreSQL: pgsql/src/port/copydir.c,v 1.13 2005/09/02 18:55:32 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -88,11 +88,16 @@ copydir(char *fromdir, char *todir, bool recurse)
8888
static void
8989
copy_file(char *fromfile, char *tofile)
9090
{
91-
char buffer[8 * BLCKSZ];
91+
char *buffer;
9292
int srcfd;
9393
int dstfd;
9494
int nbytes;
9595

96+
/* Use palloc to ensure we get a maxaligned buffer */
97+
#define COPY_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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy