> -----Original Message-----
> From: edk2-devel [mailto:[email protected]] On Behalf Of
> [email protected]
> Sent: Thursday, February 18, 2016 7:52 AM
> To: [email protected]
> Cc: Carsey, Jaben <[email protected]>; Qiu, Shumin
> <[email protected]>
> Subject: [edk2] [PATCH] ShellPkg: Increase reallocation size for temp memory
> files
> Importance: High
> 
> ShellPkg: Increase reallocation size for temp memory files
> 
> If data of any real size were to be piped from one command to another, an
> inordinate amount of time could be taken up by reallocating memory that is
> only 10 bytes bigger than what is currently needed. Also, this could cause
> unwelcome memory fragmentation.
> 
> Added a define to control how much memory is reallocated beyond that
> which is currently needed. Set it to 1K vs. the original 10 bytes.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jim Dailey
> ---
> ShellPkg/Application/Shell/FileHandleWrappers.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/ShellPkg/Application/Shell/FileHandleWrappers.c
> b/ShellPkg/Application/Shell/FileHandleWrappers.c
> index a9117be..1a61521 100644
> --- a/ShellPkg/Application/Shell/FileHandleWrappers.c
> +++ b/ShellPkg/Application/Shell/FileHandleWrappers.c
> @@ -18,6 +18,8 @@
> #include "Shell.h"
> #include "FileHandleInternal.h"
> 
> +#define MEM_WRITE_REALLOC_SIZE 1024

Could this name change to something more clear?  This is not the allocate size, 
this is more like the reallocated overhead that is allocated extra in case we 
have a sequence of reallocates...


> +
> /**
> File style interface for console (Open).
> 
> @@ -1398,8 +1400,8 @@ FileInterfaceMemWrite(
> // Unicode
> //
> if ((UINTN)(MemFile->Position + (*BufferSize)) > (UINTN)(MemFile-
> >BufferSize)) {
> - MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + (*BufferSize) + 10, MemFile->Buffer);
> - MemFile->BufferSize += (*BufferSize) + 10;
> + MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + (*BufferSize) + MEM_WRITE_REALLOC_SIZE,
> MemFile->Buffer);
> + MemFile->BufferSize += (*BufferSize) + MEM_WRITE_REALLOC_SIZE;
> }
> CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer,
> *BufferSize);
> MemFile->Position += (*BufferSize); @@ -1415,8 +1417,8 @@
> FileInterfaceMemWrite(
> }
> AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);
> if ((UINTN)(MemFile->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(MemFile-
> >BufferSize)) {
> - MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + AsciiStrSize(AsciiBuffer) + 10, MemFile-
> >Buffer);
> - MemFile->BufferSize += AsciiStrSize(AsciiBuffer) + 10;
> + MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize),
> (UINTN)(MemFile->BufferSize) + AsciiStrSize(AsciiBuffer) +
> MEM_WRITE_REALLOC_SIZE, MemFile->Buffer);
> + MemFile->BufferSize += AsciiStrSize(AsciiBuffer) +
> + MEM_WRITE_REALLOC_SIZE;
> }
> CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer,
> AsciiStrSize(AsciiBuffer));
> MemFile->Position += (*BufferSize / sizeof(CHAR16));
> --
> 2.7.1.windows.1
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to