Archive for March, 2010

default icons for apache?

March 11th, 2010

When I make a dir “icons” under the root of a virtual server, for example, http://localhost:8088. It just covers what I put under this folder and goes to a default icon folder seems to be a part of apache. Why?

show / download image with PHP

March 9th, 2010

To show a image in browser:

$file_path = ICON_DIR . $_GET['f'];
// TODO check file_path security
$file_name = basename($_GET['f']);
$fileLineArray = file($file_path);
header(‘Content-Type: image/jpeg’);
foreach($fileLineArray as $fileLine)
echo $fileLine;

To force the browser to show the download dialogue, add a attachment header:

header(“Content-disposition: attachment; filename=$file_name”);

c++ vector memory taken

March 2nd, 2010

Here is a experiment about how much memory will a vector array take with different size on a 64bit machine with a 64bit OS (Ubuntu).

Vector Arr Size   Memory
10K * 1             208K
10K * 10           688K
10K * 100         5.4M
10K * 1000       52.8M
12K * 100         12.3M
100K * 10         10M
300K * 10         30M
300K * 100        158M

Note: 10K * 1 means an array of 10K vectors with each vector having 1 int element.

array initialization in C++

March 1st, 2010

An important point about array initializaiton in C++ is that a static array won’t assign default values to it’s elements, but a dynamic one will. At least it’s like this with g++.

Here is an example:

int main(int argc, char* argv[]) {
  size_t n(100000);

  // This works
  unsigned short *ords;
  ords = new unsigned short[n];
  // or
  //ords = new unsigned short[n]();

  // This doesn't work
  //unsigned short ords[n];

  bool noProblem = true;
  for(size_t i = 0; i != n; ++i) {
    if(ords[i] != 0) {
      noProblem = false;
    cout << "No problem" << endl;
    cout << "It doesn't work" << endl;