ByteBuffer를 이용한 "빠른" 내용 복사

dohuon의 이미지

안녕하세요? 한 3일쩨 고생하고 있네요 ^^;

run length로 압축된 파일을 읽어서 압축을 푼 다음에 ByteBuffer에 너야 합니다.

파일은 filechannel을 이용해 빠르게 잘 읽었습니다. 압축을 푸는 부분에서 시간이 너무 오래 걸립니다.

압축된 파일을 ByteBuffer로 받아서

1바이트 - 시그널 (데이터가 몇번 반복되어 있나)
4바이트 - 데이터

이렇게 무수히 반복되는 데이터를 ByteBuffer에 풀어 넣어 리턴 하면 됩니다.

1. 바이트 어레이를 써서 복사하면 무지 느립니다.
2. 아래 예제와 같이 바이트 버퍼를 여러개 쓰는 방법을 써도 느립니다
ㅠㅠ

	int repetition;
    private ByteBuffer unCompress(FileChannel bbuf){
 
    	ByteBuffer output = ByteBuffer.allocateDirect(1048576);
    	ByteBuffer index = ByteBuffer.allocateDirect(1);
    	ByteBuffer rawData = ByteBuffer.allocateDirect(4);
 
    	try{
 
    		bbuf.position(0);
 
    		while(bbuf.position() > bbuf.size() ){
    		bbuf.read(index); // 시그널(인덱스) 읽기
    		bbuf.read(rawData); // 반복될 데이터
 
    		repetition = (int)(index.get() & 0xff); // 몇번 반복해야 할까?
 
    			while(repetition > 0) { 
    				output.put(rawData); // 데이터를 내보낼 bytebuffer에 반복하며 기록
    				repetition--;
    			}
    		}    	
 
    		output.position(0);
	    return output;
 
    	} catch (Exception e){
    	return output;  
    	}
    }
dalant019의 이미지

제일 안쪽 while문에 있는 output.put을 말하는 건가요? 만약 맞다면,
한번의 index와 rawData를 읽고 이에 대한 출력을 만드는 것을 한 단계라고 했을 때,
이 단계에서 출력을 따로 따로 하지 마시고 어느 정도 메모리에 모은 다음 그 모은 묶음을 출력하셔서 출력횟수를 줄여 보시는 건 어떨까 생각됩니다.
출력 부분이 오버헤드라 생각하고 그 횟수를 줄일 수 있는 제 부족한 소견을 말씀 드린 거예요.^^ 잘 안되더라도 용서를... 근데 워낙 라이브러리 전문가들이 라이브러리를 오버헤드까지 생각해서 잘 만들었을 터인지라... output.put 내부에서 알아서 버퍼를 만들어 출력을 지혜롭게 하고 있는지 모르겠군요--;; 아마 그럴 확률이 큼...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.