'Enjoy > 출사' 카테고리의 다른 글
출사 - 벽초지 (3) | 2008.09.29 |
---|---|
출사 - 중남미문화원, 벽초지 (2) | 2008.09.29 |
대전 한밭수목원 출사 (5) | 2008.07.07 |
워크샵 출사 (2) | 2008.06.24 |
서울숲 - 풍경 (4) | 2008.04.27 |
출사 - 벽초지 (3) | 2008.09.29 |
---|---|
출사 - 중남미문화원, 벽초지 (2) | 2008.09.29 |
대전 한밭수목원 출사 (5) | 2008.07.07 |
워크샵 출사 (2) | 2008.06.24 |
서울숲 - 풍경 (4) | 2008.04.27 |
작은 집단의 자료에서 계산한 여러 통계자료를 기준으로 이름의 성별과 시대별 특징을 알려드립니다. 정교하게 조절된 통계가 아니므로 재미로만 보세요. :)
관련글 트랙백과 댓글은 블로그로 보내주세요. 여러 명을 한꺼번에 알아보시려면 여기에서 하실 수 있습니다.
Mr. WiseBell (3) | 2008.10.21 |
---|---|
코드기어스 2기 25화(完) (0) | 2008.09.30 |
저녁식사와 사진과 MP 300 (4) | 2008.05.20 |
오늘의 시도2 "키위 에이드" (6) | 2008.05.12 |
오늘의 시도 "에이드" (3) | 2008.05.12 |
코드기어스 2기 25화(完) (0) | 2008.09.30 |
---|---|
터미널... (0) | 2008.06.13 |
오늘의 시도2 "키위 에이드" (6) | 2008.05.12 |
오늘의 시도 "에이드" (3) | 2008.05.12 |
"아이언맨" 시작되다. (3) | 2008.05.07 |
Any "tips and tricks" presentation on the .NET Base Class Libraries will tell you that StringBuilder is better than String::Concat. Here's how that looks:
void StringBuild::build(int loops) { String* block = "123456789012345678901234567890"; StringBuilder* result = new StringBuilder(); for (int i=0; i<loops;i++) result->Append(block); String* realresult = result->ToString(); Console::WriteLine(realresult->Length.ToString()); return; }
The only hassle is remembering to call ToString() on the StringBuilder when you've finished building it. The code is simple to write and to read, and it's much much faster than the String::Concat() case. But it's not the fastest, at least not always.
StringBuilder works by allocating more memory than you need, and by tacking the new strings into that buffer. Every time you need the buffer to enlarge, it doubles in size. That approach was chosen as a trade-off between allocating too much memory and wasting a lot of time allocating little extra bits over and over again. The starting size is implementation-specific, but in most cases it's 16 characters. You can pass an integer to the StringBuilder constructor to bump up the initial allocation if you know what you'll need: That will save you the extra allocations but it won't save you all the testing to see whether you've exceeded your capacity or not.
So, because this is C++ after all, let's do something they can't do in VB and play with pointers a little. Look at this code:
void StringBuffer::build(int loops) { char* block = "123456789012345678901234567890"; int delta = strlen(block); char* buffer = new char[loops*strlen(block)+1]; char* p = buffer; for (int i=0; i<loops;i++) { strcpy(p,block); p += delta; } String* result = buffer; Console::WriteLine(result->Length.ToString()); return; }
Whenever you work with char* strings, you have to remember when to add an extra character for the \0 or when to move past it or before it or whatever. In this code, the delta, how much we move forward each time, is deliberately set to exactly the strlen of block—normally you would add 1 to allow room for the \0, but I want the first character of the next append to overwrite the \0 so we have one long, contiguous string at the end.
This code works, and it is faster than StringBuilder. That's not surprising, because I don't have to test to see whether I am exceeding my capacity, and I don't have to allocate more memory. Because I'm steering clear of the managed heap except for the final string, I'm probably not exercising the garbage collector either. So what is surprising is that's it's not very much faster than StringBuilder: about 10-20% less time for the same number of loops. And this is for a special case where I knew the exact length of the buffer in the end. For the general case where you're gluing together an unknown number of strings, each of an unknown length, you're not going to beat StringBuilder with something you write yourself. That's worth knowing, isn't it?
이상형을 찾아서~ (6) | 2009.12.16 |
---|---|
NUnit (0) | 2009.09.09 |
Call Level Interface (CLI) (2) | 2009.04.15 |
Visual C# .NET 에서 Word 문서 생성 (0) | 2008.07.25 |
C#에서 동일한 프로그램에 중복 실행을 방지하는 방법 (2) | 2008.01.31 |
재료썰기 |
재료 다지기.. ( 믹서야 ㅠ.ㅠ) |
도마 이도류 노현종 데슈 ( -_)/ |
잘 갈아만든(?) 재료를 용기에 담는다. |
올리고당을 넣어줍니다. |
재료를 잘 섞어줍니다. |
탄산수를 넣어주고 혼합해 줍니다. |
완성된 음료를 컵에 담습니다. |
터미널... (0) | 2008.06.13 |
---|---|
저녁식사와 사진과 MP 300 (4) | 2008.05.20 |
오늘의 시도 "에이드" (3) | 2008.05.12 |
"아이언맨" 시작되다. (3) | 2008.05.07 |
월광 (0) | 2008.04.27 |
재료준비 : "탄산수, 올리고당, 파인애플" |
파인애플을 갈아(?)주세요 |
다 갈아진(?) 모습 ( 믹서가 없어요 ㅠ.ㅠ ) |
혼합을 위해 용기에 담아요 |
탄산수를 500ml 넣어줍니다. |
올리고당을 충분히 넣어줍니다. |
잘 저어서 섞어 줍니다. ( 플라스틱 병등에 담아 흔들어도 될듯) |
얼음을 담아놓은 컵에 담아 마셔줍니다. |
저녁식사와 사진과 MP 300 (4) | 2008.05.20 |
---|---|
오늘의 시도2 "키위 에이드" (6) | 2008.05.12 |
"아이언맨" 시작되다. (3) | 2008.05.07 |
월광 (0) | 2008.04.27 |
"Taken"을 보다. (0) | 2008.04.15 |
** 주인공 '토니 스타크'역의 '로버트 다우니 주니어'가 3편까지 출연이 약속되어있다고 하니 시리즈물을 가볍게 즐겨보시고자 해도 괜찬은 선택이 될것 같습니다.
오늘의 시도2 "키위 에이드" (6) | 2008.05.12 |
---|---|
오늘의 시도 "에이드" (3) | 2008.05.12 |
월광 (0) | 2008.04.27 |
"Taken"을 보다. (0) | 2008.04.15 |
코드기어서 R2 (2) | 2008.04.14 |
충분히 셔터를 날려주지 못해 건진 사진이 얼마 없는 가운데... 가릴것없이 올려본다..
충분한 셔터고 좋은 사진을 만드는걸까?
사진을 찍는동안... 5D와 30D를 교대로 서봤는데.. 아무리.. 좋은 사진은 찍는사람이 중요하다고
하지만... 왠지 5D와 30D 앞에서 작아만지는 350D 였다... OTL
어여 기계탓을 하지 않을정도가 되야 할텐데 ( -_);;
서울숲의 첫 얼굴.. 벤치?
열심히 나무위를 돌아다니는 개미들..
숲을 지키는 개미.. 나무위를 거닐다..
화단의 나무.. |
나무와 벤치 |
꽃밭..
사슴의 옆얼굴
사슴의 뒷태
엿못위의 하트
두송이의 꽃
출사 - 벽초지 (3) | 2008.09.29 |
---|---|
출사 - 중남미문화원, 벽초지 (2) | 2008.09.29 |
대전 한밭수목원 출사 (5) | 2008.07.07 |
워크샵 출사 (2) | 2008.06.24 |
꽃이 피었습니다. (2) | 2008.06.16 |