Exemplo n.º 1
0
int64 CSegmentPool::Init( const RemoteFileInfo &remoteFileInfo, INT nCocurrent )
{
	m_remoteFileInfo = remoteFileInfo;
	MYTRACE(_T("_AllocSegments : RandomAccess:%d  ContentLength:%I64d\r\n"), m_remoteFileInfo.bRandomAccess, m_remoteFileInfo.fileSize);
	
	release_array(parts);
	m_iDownloaded = 0;
	if (m_remoteFileInfo.bRandomAccess && m_remoteFileInfo.fileSize>0)
	{		
		int64 iContentLength = 0;
		CSegmentInfoFile segfile(m_strFilename);
		if(segfile.Load(iContentLength, m_iDownloaded, parts) && iContentLength==m_remoteFileInfo.fileSize)
		{
			;
		}
		else
		{
			release_array(parts);
			// If load failed, and filesize not match the content-length 				
			iContentLength = m_remoteFileInfo.fileSize;
			m_iDownloaded = 0;

			int nblock = 0;
			int64 block_size = 0;
			if (iContentLength > (MIN_BLOCK * nCocurrent))
			{
				nblock = nCocurrent;
				block_size = iContentLength/nCocurrent;
			}
			else
			{
				nblock = (iContentLength + MIN_BLOCK - 1) / MIN_BLOCK;
				block_size = iContentLength/nblock;
			}
			for (int i=0; i<nblock; ++i)
			{
				parts.push_back( new Segment(i, i*block_size, i*block_size+block_size) );
			}
			parts[parts.size()-1]->endposition = iContentLength;
		}
	}
	else
	{
		parts.push_back( new Segment(0, 0, m_remoteFileInfo.fileSize > 0 ? m_remoteFileInfo.fileSize : -1) );
	}

	for(size_t i=0; i<parts.size(); ++i)
	{
		Segment *s = parts[i];
		s->isDone() ? parts_done.push_back( s ) : parts_queuing.push_back( s );
	}
	return m_iDownloaded;
}
int main()
{
  int i=1, j;
  int *a=create_array(1);

  a = insert(a,i,5);
  i++;
  a = insert(a,i,2);
  i++;
  a = insert(a,i,1);
  i++;
  a = insert(a,i,7);
  i++;
  a = insert(a,i,4);
  i++;
  a = insert(a,i,3);

  for(j=0; j<i; j++)
    printf("%d\n",a[j]);  

  release_array(a);

  return 0;
}